*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="ointroduceri.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS container_valoare_decontata AS container 
 	*< CLASSDATA: Baseclass="container" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Label1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Text1" UniqueID="" Timestamp="" />

	*<PropValue>
		BackColor = 255,255,255
		BorderColor = 255,255,255
		Height = 28
		Name = "container_valoare_decontata"
		Width = 245
	*</PropValue>

	ADD OBJECT 'Label1' AS label WITH ;
		BackStyle = 0, ;
		Caption = "Valoare decontatã", ;
		FontCharSet = 238, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 7,118,177, ;
		Height = 17, ;
		Left = 3, ;
		Name = "Label1", ;
		Top = 6, ;
		Width = 108
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'Text1' AS textbox WITH ;
		ControlSource = "pnValoareDecontata", ;
		FontCharSet = 238, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Format = "rk", ;
		Height = 23, ;
		InputMask = (get_mask(12,gnPC)), ;
		Left = 113, ;
		Name = "Text1", ;
		SpecialEffect = 1, ;
		Top = 3, ;
		Width = 129
		*< END OBJECT: BaseClass="textbox" />
	
	PROCEDURE Text1.LostFocus
		IF pnValoareDecontata > thisform.nTotal
			pnValoareDecontata = thisform.nTotal
			this.Refresh 
		ENDIF 
		
		pnCheltuieliDirecte = thisform.nTotal - pnValoareDecontata  
	ENDPROC

ENDDEFINE

DEFINE CLASS facturi_retur AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Ct_grid_order1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column1.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column1.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column2.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column2.Check1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column3.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column3.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column4.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column4.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column5.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column5.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column6.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column6.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column7.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column7.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column8.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column8.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column9.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column9.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column10.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.Column10.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.cSerie_act.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1._GRID1.cSerie_act.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_n1n2_simplu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Resizable1" UniqueID="" Timestamp="" />

	#INCLUDE "..\include\foxpro.h"
	*<PropValue>
		BorderStyle = 1
		DoCreate = .T.
		Height = 460
		Name = "facturi_retur"
		Width = 662
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 662
		_shape1.ZOrderSet = 1
		_shape2.Height = 29
		_shape2.Left = 599
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 63
		_shape2.ZOrderSet = 2
		Lb_titlu_alb_b121.Caption = "Selectati facturile pentru retur"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 5
		Lb_titlu_alb_b121.ZOrderSet = 3
		BUT_TERMIN1.Left = 631
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 3
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 4
		GRIDSORT1.Name = "GRIDSORT1"
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 601, ;
		Name = "But_renunt1", ;
		TabIndex = 4, ;
		Top = 1, ;
		ZOrderSet = 6
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Clb_n1n2_simplu1' AS clb_n1n2_simplu WITH ;
		BorderColor = 7,118,177, ;
		BorderWidth = 2, ;
		Height = 30, ;
		Left = 362, ;
		Name = "Clb_n1n2_simplu1", ;
		TabIndex = 1, ;
		Top = 68, ;
		Width = 290, ;
		ZOrderSet = 5, ;
		tx_n1.ControlSource = "pdDatai", ;
		tx_n1.Left = 130, ;
		tx_n1.Name = "tx_n1", ;
		tx_n1.Top = 3, ;
		Lb_simplu1.Caption = "Facturi din perioada:", ;
		Lb_simplu1.Left = 8, ;
		Lb_simplu1.Name = "Lb_simplu1", ;
		Lb_simplu1.Top = 7, ;
		tx_n2.ControlSource = "pdDataf", ;
		tx_n2.Left = 210, ;
		tx_n2.Name = "tx_n2", ;
		tx_n2.Top = 3
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_order1' AS ct_grid_order WITH ;
		cnumecursor = crs_facturi_emise, ;
		Height = 418, ;
		Left = 7, ;
		Name = "Ct_grid_order1", ;
		TabIndex = 2, ;
		Top = 41, ;
		Width = 648, ;
		ZOrderSet = 0, ;
		_GRID1.Column1.ControlSource = "nrcrt()", ;
		_GRID1.Column1.FontName = "Arial Narrow", ;
		_GRID1.Column1.Name = "Column1", ;
		_GRID1.Column1.Width = 24, ;
		_GRID1.Column10.ColumnOrder = 11, ;
		_GRID1.Column10.ControlSource = "totdebit-totcredit", ;
		_GRID1.Column10.FontName = "Arial Narrow", ;
		_GRID1.Column10.InputMask = (get_mask(12,gnPc)), ;
		_GRID1.Column10.Name = "Column10", ;
		_GRID1.Column10.Width = 81, ;
		_GRID1.Column11.ColumnOrder = 3, ;
		_GRID1.Column11.ControlSource = "serie_act", ;
		_GRID1.Column11.FontName = "Arial Narrow", ;
		_GRID1.Column11.Name = "cSerie_act", ;
		_GRID1.Column11.Width = 53, ;
		_GRID1.Column2.Alignment = 2, ;
		_GRID1.Column2.ControlSource = "ceck", ;
		_GRID1.Column2.FontName = "Arial Narrow", ;
		_GRID1.Column2.Name = "Column2", ;
		_GRID1.Column2.Sparse = .F., ;
		_GRID1.Column2.Width = 31, ;
		_GRID1.Column3.ColumnOrder = 4, ;
		_GRID1.Column3.ControlSource = "nract", ;
		_GRID1.Column3.FontName = "Arial Narrow", ;
		_GRID1.Column3.Name = "Column3", ;
		_GRID1.Column4.ColumnOrder = 5, ;
		_GRID1.Column4.ControlSource = "dataact", ;
		_GRID1.Column4.FontName = "Arial Narrow", ;
		_GRID1.Column4.Name = "Column4", ;
		_GRID1.Column4.Width = 63, ;
		_GRID1.Column5.ColumnOrder = 6, ;
		_GRID1.Column5.ControlSource = "datascad", ;
		_GRID1.Column5.FontName = "Arial Narrow", ;
		_GRID1.Column5.Name = "Column5", ;
		_GRID1.Column5.Width = 70, ;
		_GRID1.Column6.ColumnOrder = 7, ;
		_GRID1.Column6.ControlSource = "cont", ;
		_GRID1.Column6.FontName = "Arial Narrow", ;
		_GRID1.Column6.Name = "Column6", ;
		_GRID1.Column6.Width = 31, ;
		_GRID1.Column7.ColumnOrder = 8, ;
		_GRID1.Column7.ControlSource = "acont", ;
		_GRID1.Column7.FontName = "Arial Narrow", ;
		_GRID1.Column7.Name = "Column7", ;
		_GRID1.Column7.Width = 33, ;
		_GRID1.Column8.ColumnOrder = 9, ;
		_GRID1.Column8.ControlSource = "totdebit", ;
		_GRID1.Column8.FontName = "Arial Narrow", ;
		_GRID1.Column8.InputMask = (get_mask(12,gnPc)), ;
		_GRID1.Column8.Name = "Column8", ;
		_GRID1.Column8.Width = 89, ;
		_GRID1.Column9.ColumnOrder = 10, ;
		_GRID1.Column9.ControlSource = "totcredit", ;
		_GRID1.Column9.FontName = "Arial Narrow", ;
		_GRID1.Column9.InputMask = (get_mask(12,gnPc)), ;
		_GRID1.Column9.Name = "Column9", ;
		_GRID1.Column9.Width = 88, ;
		_GRID1.ColumnCount = 11, ;
		_GRID1.FontName = "Arial Narrow", ;
		_GRID1.Height = 348, ;
		_GRID1.Left = 6, ;
		_GRID1.Name = "_GRID1", ;
		_GRID1.Panel = 1, ;
		_GRID1.RecordSource = "crs_facturi_emise", ;
		_GRID1.Top = 62, ;
		_GRID1.Width = 639, ;
		Titlu.Left = 9, ;
		Titlu.Name = "Titlu", ;
		Titlu.Top = 3, ;
		Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.Text.Name = "Text"
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column1.Header1' AS header WITH ;
		Caption = "Nr.", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column1.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column10.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Sold", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column10.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column2.Check1' AS checkbox WITH ;
		Alignment = 0, ;
		Caption = "", ;
		Centered = .T., ;
		FontName = "Arial Narrow", ;
		Height = 17, ;
		Left = 9, ;
		Name = "Check1", ;
		Top = 40, ;
		Width = 60
		*< END OBJECT: BaseClass="checkbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column2.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Alege", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column3.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Nr.factura", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column3.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column4.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Data factura", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column4.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column5.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Data scadenta", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column5.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column6.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Cont", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column6.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column7.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Analitic", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column7.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column8.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Total factura", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column8.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column9.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Achitat", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.Column9.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Ct_grid_order1._GRID1.cSerie_act.Header1' AS header WITH ;
		Alignment = 0, ;
		Caption = "Serie factura", ;
		FontName = "Arial Narrow", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Ct_grid_order1._GRID1.cSerie_act.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Resizable1' AS resizable_class WITH ;
		Left = 271, ;
		Name = "Resizable1", ;
		repositionlist = _shape Urmator But_termin But_renunt Clb_n1n2_simplu Titlufrumos Ct_grid_order, ;
		resizelist = _shape Urmator But_termin But_renunt Clb_n1n2_simplu Titlufrumos Ct_grid_order, ;
		Top = 31
		*< END OBJECT: ClassLib="solution.vcx" BaseClass="custom" />
	
	PROCEDURE inainte_de_do_termin
		lcSel = this.ct_grid_order1.cnumecursor 
		SELECT (lcSel)
		COUNT FOR ceck = 1 TO lnAlese
		IF lnAlese = 0
			amessagebox('Alegeti o factura!',0+16,'Atentie')
			RETURN .f.
		ENDIF 
		
	ENDPROC

	PROCEDURE Show
		LPARAMETERS nStyle
		this.ct_grid_order1.initializare(.t.)
		
		i = 0
		For Each loColumn In Thisform.ct_grid_order1._GRID1.Columns
			i = i + 1
			With loColumn
				If !Empty(loColumn.ControlSource)
		
					* Save default caption, color and font
		
					lcOldCaption   = loColumn.Header1.Caption
					lcOldFontName = loColumn.Header1.FontName
					lnOldForeColor = loColumn.Header1.ForeColor
					llOldFontUnderline = loColumn.Header1.FontUnderline
		
					* Name Header Obj after ControlSource
		
					lcControlSrc = loColumn.ControlSource
					lnControlSrc = Rat(".", lcControlSrc) + 1
					lcControlSrc = Substr(lcControlSrc, lnControlSrc)
					
					*	Metoda dupa care se face ordonarea relativa la grid
					lcMethodName = 'parent.corderby_assign'
					lcPropColOrder = 'parent.cOrder'
					lcPropSensOrder = 'parent.cAsc'
					* Remove old and create new header
		
					.RemoveObject("Header1")
					.AddObject("grh"+ALLTRIM(STR(i)), ;
						"PSHeader", ;
						lcOldCaption, lcOldFontName,lnOldForeColor,llOldFontUnderline,lcMethodName,lcControlSrc)
		
					If Upper(Alltrim(lcControlSrc)) = Upper(Alltrim(this.ct_grid_order1.corder))
						lcCuloare = [locolumn.grh] + ALLTRIM(STR(i)) + [.forecolor = RGB(0,0,255)]
						&lcCuloare
						lcUnderline = [locolumn.grh] + ALLTRIM(STR(i)) + [.FontUnderline = .t.]
						&lcUnderline
					Endif
				Endif
			Endwith
		ENDFOR
		
		
		
		
	ENDPROC

	PROCEDURE Clb_n1n2_simplu1.tx_n1.Valid
		IF EMPTY(this.Parent.tx_n2.value)
			this.Parent.tx_n2.value=this.value
			this.Parent.tx_n2.Refresh
		ENDIF 
	ENDPROC

	PROCEDURE Clb_n1n2_simplu1.tx_n2.LostFocus
		thisform.LockScreen = .t.
		thisform.ct_grid_order1.initializare(.t.)
		thisform.ct_grid_order1.SetFocus 
		thisform.LockScreen = .f.
	ENDPROC

	PROCEDURE Ct_grid_order1.initializare
		PARAMETERS tlNumerotare
		
		llNrOrd = tlNumerotare
		
		*** CREEZ CURSORUL INITIAL
		
		lcTitlu = This.cTitlu
		lcOrder = this.corder 
		lcNumeCursor = this.cnumecursor 
		lcSql = This.cSelect
		lnSucces = goExecutor.oExecute(lcSql,'crs_temp')
		
		IF lnSucces < 0
			amessagebox(goExecutor.cEroare,0+16,"Eroare")
			RETURN 
		ENDIF 
		
		save_grid(This._grid1)
		
		IF USED(lcNumeCursor)
			USE IN &lcNumeCursor
		ENDIF 
		
		SELECT ceck, serie_act, nract, TTOD(dataact) as dataact,TTOD(datascad) as datascad,cont,acont,totdebit,totcredit,totdebit-totcredit,id_fact ;
		FROM crs_temp INTO CURSOR (lcNumeCursor) READWRITE 
		
		USE IN crs_temp
		
		IF llNrOrd
			DO nrord WITH lcNumeCursor
			this._griD1.LockColumns = 1
		ENDIF 	
		
		restore_grid(This._grid1)
		
		SELECT (lcNumeCursor)
		GO TOP 
	ENDPROC

	PROCEDURE _shape1.DblClick
		IF thisform.WindowState = 2
			thisform.WindowState = 0
		ELSE 
			thisform.WindowState = 2 
		ENDIF 
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_alege_prod_cant AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Command1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txt_produs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Label1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtCant" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_clb_gestiune" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_clb_produs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Label2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtLot" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Label3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtSerie" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_cauta_gestiune
		*m: do_cauta_produs
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		Caption = "Form"
		DoCreate = .T.
		Height = 188
		Name = "frm_alege_prod_cant"
		Width = 353
		_SHAPE1.Name = "_SHAPE1"
		_SHAPE2.Height = 29
		_SHAPE2.Left = 292
		_SHAPE2.Name = "_SHAPE2"
		_SHAPE2.Top = 0
		_SHAPE2.Width = 61
		LB_TITLU_ALB_B121.Caption = "Productie"
		LB_TITLU_ALB_B121.Name = "LB_TITLU_ALB_B121"
		LB_TITLU_ALB_B121.TabIndex = 8
		BUT_TERMIN1.Left = 322
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 6
		BUT_TERMIN1.Top = 1
		GRIDSORT1.Left = 240
		GRIDSORT1.Name = "GRIDSORT1"
		GRIDSORT1.Top = 12
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 292, ;
		Name = "But_renunt1", ;
		TabIndex = 7, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Command1' AS commandbutton WITH ;
		Caption = "Cauta articol", ;
		Height = 27, ;
		Left = 25, ;
		Name = "Command1", ;
		TabIndex = 9, ;
		Top = 257, ;
		Width = 84
		*< END OBJECT: BaseClass="commandbutton" />

	ADD OBJECT 'Ct_clb_gestiune' AS ct_clb_cautare_var WITH ;
		cconditie = EMPTY(NVL(pnId_gestiune,0)), ;
		cprocedura = thisform.do_cauta_gestiune, ;
		cvar_afisata = pcGestiune, ;
		Height = 31, ;
		Left = 12, ;
		Name = "Ct_clb_gestiune", ;
		TabIndex = 5, ;
		Top = 150, ;
		Width = 337, ;
		shape_cautare.Height = 29, ;
		shape_cautare.Left = 1, ;
		shape_cautare.Name = "shape_cautare", ;
		shape_cautare.Top = 1, ;
		shape_cautare.Width = 305, ;
		img_cautare.Left = 310, ;
		img_cautare.Name = "img_cautare", ;
		img_cautare.Top = 5, ;
		lb_cautare.Caption = "Gestiune destinatie", ;
		lb_cautare.Name = "lb_cautare", ;
		tx_cautare.Left = 119, ;
		tx_cautare.Name = "tx_cautare", ;
		tx_cautare.Top = 4
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_clb_produs' AS ct_clb_cautare_var WITH ;
		cconditie = EMPTY(NVL(pnId_articol,0)), ;
		cprocedura = thisform.do_cauta_produs, ;
		cvar_afisata = pcDenumire, ;
		Height = 31, ;
		Left = 11, ;
		Name = "Ct_clb_produs", ;
		TabIndex = 1, ;
		Top = 43, ;
		Width = 337, ;
		shape_cautare.Height = 29, ;
		shape_cautare.Left = 1, ;
		shape_cautare.Name = "shape_cautare", ;
		shape_cautare.Top = 1, ;
		shape_cautare.Width = 305, ;
		img_cautare.Left = 309, ;
		img_cautare.Name = "img_cautare", ;
		img_cautare.Top = 5, ;
		lb_cautare.Caption = "Produs", ;
		lb_cautare.Name = "lb_cautare", ;
		tx_cautare.Left = 119, ;
		tx_cautare.Name = "tx_cautare", ;
		tx_cautare.Top = 4
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Label1' AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Cantitate", ;
		FontSize = 10, ;
		Height = 18, ;
		Left = 17, ;
		Name = "Label1", ;
		TabIndex = 11, ;
		Top = 78, ;
		Width = 54
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'Label2' AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Lot", ;
		FontSize = 10, ;
		Height = 18, ;
		Left = 17, ;
		Name = "Label2", ;
		TabIndex = 13, ;
		Top = 103, ;
		Width = 20
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'Label3' AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Serie", ;
		FontSize = 10, ;
		Height = 18, ;
		Left = 17, ;
		Name = "Label3", ;
		TabIndex = 12, ;
		Top = 128, ;
		Width = 32
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'txt_produs' AS textbox WITH ;
		Height = 23, ;
		Left = 120, ;
		Name = "txt_produs", ;
		TabIndex = 10, ;
		Top = 259, ;
		Width = 120
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'txtCant' AS textbox WITH ;
		ControlSource = "pnCant", ;
		FontSize = 10, ;
		Format = "rk", ;
		Height = 23, ;
		InputMask = (get_mask(10,gnPcant)), ;
		Left = 84, ;
		Name = "txtCant", ;
		TabIndex = 2, ;
		Top = 75, ;
		Width = 131
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'txtLot' AS textbox WITH ;
		ControlSource = "pcLot", ;
		FontSize = 10, ;
		Format = "!K", ;
		Height = 23, ;
		Left = 60, ;
		Name = "txtLot", ;
		TabIndex = 3, ;
		Top = 100, ;
		Width = 155
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'txtSerie' AS textbox WITH ;
		ControlSource = "pcSerie", ;
		FontSize = 10, ;
		Format = "!K", ;
		Height = 23, ;
		Left = 60, ;
		Name = "txtSerie", ;
		TabIndex = 4, ;
		Top = 125, ;
		Width = 155
		*< END OBJECT: BaseClass="textbox" />
	
	PROCEDURE do_cauta_gestiune
		Local loCauta
		loCauta = caut_gestiune(4,gnidUtil)
		
		If !Empty(Nvl(loCauta.id_gestiune,0))
			pnid_gestiune = loCauta.id_gestiune
			pcGestiune = loCauta.nume_gestiune
		
			Thisform.but_teRMIN1.SetFocus()
		Else
			pnid_gestiune = Null
			pcGestiune = []
		Endif
	ENDPROC

	PROCEDURE do_cauta_produs
		Store "" To loCauta
		
		lcFiltru = []
		lcSchema = []
		lcOrder = [nume_articol]
		lccoloane = [nume_articol,codmat,um,cont]
		lcTitlu = [Alegeti produsul]
		lcTitluColoane = [Denumire,Cod Material,UM,Cont]
		llMultipleArticles = .F.
		*lcSelect = [select a.denumire,a.codmat,a.um, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa,a.dnf,a.cont, a.acont, a.inactiv, a.id_articol from ] + gcS + [.vnom_articole a ]
		*!*	lcSelect = [select id_articol,id_pol,pret,um,nume_articol,codmat, cont ] + ;
		*!*		[ from com_vpreturi_utilizator where id_util = ?gnIdUtil and id_pol in ] + ;
		*!*		[ (select varvalue as id_pol from optiuni where vartype = 'NUMERIC' AND varname = ?pcOptiune ) ] 
		*!*	modificare ROAPRODUCTIE v 2.0.2
		*!*	pcOptiune = 'ID_LISTA_PRETURI_PV_PRODUCTIE'
		*!*	lcSelect = [select id_articol,id_pol,pret,um,nume_articol,codmat, cont ] + ;
		*!*		[ from com_vpreturi_utilizator ]
		*!*	lcFiltruOriginal = [ id_util = ?gnIdUtil and id_pol in ] + ;
		*!*		[ (select varvalue as id_pol from optiuni where vartype = 'NUMERIC' AND varname = ?pcOptiune ) ]
		lcSelect = [select id_articol,id_pol,pret,um,nume_articol,codmat, cont, in_crm, in_stoc ] + ;
			[ from com_vpreturi_utilizator ]
		lcFiltruOriginal = [ in_stoc = 1 and id_util = ?gnIdUtil and id_pol = ?gnId_lista_preturi_pv ]
		*!*	modificare ROAPRODUCTIE v 2.0.2	^
		lcNumeProc = []
		llToateIreg = .F.
		lcPrimaColoana = []
		lnPornire = 1
		lnTipReturn = Iif(llMultipleArticles, 1, 0)
		lcIdColumn = "id_articol"
		llModParam = .T.
		
		loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn , lcIdColumn,,,,,llModParam)		&& 11.07.2007
		***------------------------------	
		pnId_articol = loCauta.id_articol
		pcDenumire = loCauta.nume_articol
		pcCont_articol = loCauta.cont
		*!*	modificare ROAPRODUCTIE v 2.0.2
		pnInStoc = loCauta.in_stoc
		pnInCrm = loCauta.in_crm
		pcUm = loCauta.um
		*!*	modificare ROAPRODUCTIE v 2.0.2	^
		
		Thisform.txtCant.SetFocus()
		
	ENDPROC

	PROCEDURE inainte_de_do_termin
		IF EMPTY(pnId_articol)
			AMESSAGEBOX('Nu ati ales produsul!')
			RETURN .F.
		ENDIF 
		
		IF EMPTY(pnId_gestiune)
			AMESSAGEBOX('Nu ati ales gestiunea!')
			RETURN .F.
		ENDIF
	ENDPROC

	PROCEDURE Command1.Click
		Store "" To loCauta
		
		lcFiltru = [1=2]
		lcSchema = []
		lcOrder = [nume_articol]
		lccoloane = [nume_articol,codmat,um,cont]
		lcTitlu = [Alegeti produsul (mouse-click pe denumire sau apasati SPACE)]
		lcTitluColoane = [Denumire,Cod Material,UM,Cont]
		llMultipleArticles = .T.
		*lcSelect = [select a.denumire,a.codmat,a.um, a.grupa, a.subgrupa, a.id_grupa, a.id_subgrupa,a.dnf,a.cont, a.acont, a.inactiv, a.id_articol from ] + gcS + [.vnom_articole a ]
		*!*	modificare ROAPRODUCTIE v 2.0.2
		*!*	pcOptiune = 'ID_LISTA_PRETURI_PV_PRODUCTIE'
		*!*	lcSelect = [select id_articol,id_pol,pret,um,nume_articol,codmat, cont ] + ;
		*!*		[from com_vpreturi_utilizator where id_util = ?gnIdUtil and id_pol in ] + ;
		*!*		[(select varvalue as id_pol from optiuni where varname = ?pcOptiune and vartype = 'NUMERIC') ] 
		lcSelect = [select id_articol,id_pol,pret,um,nume_articol,codmat,cont ] + ;
			[from com_vpreturi_utilizator where id_util = ?gnIdUtil and id_pol = ?gnID_LISTA_PRETURI_PV ]
		*!*	modificare ROAPRODUCTIE v 2.0.2	^
		lcFiltruOriginal = []
		lcNumeProc = []
		llToateIreg = .F.
		lcPrimaColoana = [denumire]
		lnPornire = 1
		lnTipReturn = Iif(llMultipleArticles, 1, 0)
		lcIdColumn = "id_articol"
		loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn , lcIdColumn)		&& 11.07.2007
		***------------------------------	
		
		pnId_articol = loCauta.id_articol
		pcDenumire = nume_articol
		pcCont_articol = cont
		thisform.txt_produs.Value = pcDenumire 
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_alege_sectie AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Ct_clb_grup" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_cauta_sectie
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		DoCreate = .T.
		Height = 89
		Name = "frm_alege_sectie"
		Width = 352
		_shape1.Name = "_shape1"
		_shape2.Height = 29
		_shape2.Left = 291
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 62
		Lb_titlu_alb_b121.Caption = "Sectia beneficiara"
		Lb_titlu_alb_b121.Left = 11
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 5
		Lb_titlu_alb_b121.Top = 6
		BUT_TERMIN1.Left = 322
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 3
		BUT_TERMIN1.Top = 1
		Gridsort1.Left = 228
		Gridsort1.Name = "Gridsort1"
		Gridsort1.Top = 7
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 292, ;
		Name = "But_renunt1", ;
		TabIndex = 4, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_clb_grup' AS ct_clb_cautare_var WITH ;
		cconditie = EMPTY(NVL(pnId_sectie,0)), ;
		cprocedura = thisform.do_cauta_sectie, ;
		cvar_afisata = pcSectie, ;
		Height = 31, ;
		Left = 11, ;
		Name = "Ct_clb_grup", ;
		TabIndex = 1, ;
		Top = 40, ;
		Width = 337, ;
		shape_cautare.Height = 29, ;
		shape_cautare.Left = 1, ;
		shape_cautare.Name = "shape_cautare", ;
		shape_cautare.Top = 1, ;
		shape_cautare.Width = 305, ;
		img_cautare.Left = 310, ;
		img_cautare.Name = "img_cautare", ;
		img_cautare.Top = 5, ;
		lb_cautare.Caption = "Sectia beneficiara", ;
		lb_cautare.Name = "lb_cautare", ;
		tx_cautare.Left = 119, ;
		tx_cautare.Name = "tx_cautare", ;
		tx_cautare.Top = 4
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />
	
	PROCEDURE do_cauta_sectie
		Local loCauta
		loCauta = caut_sectie()
		
		If !Empty(Nvl(loCauta.id_sectie,0))
			pnid_sectie = loCauta.id_sectie
			pcSectie = loCauta.sectie
		
			Thisform.but_TERMIN1.SetFocus()
		Else
			pnid_sectie = Null
			pcSectie = []
		Endif
		
	ENDPROC

	PROCEDURE inainte_de_do_termin
		IF EMPTY(NVL(pnId_sectie,0))
			AMESSAGEBOX('Nu ati ales sectia!',48,"Atentie")
			THISFORM.CT_clb_grup.SetFocus()
			RETURN .F.
		ENDIF 
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_alege_sectie_comanda AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Ct_clb_grup" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_clb_comanda" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_cauta_comanda
		*m: do_cauta_sectie
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		DoCreate = .T.
		Height = 119
		Name = "frm_alege_sectie_comanda"
		Width = 352
		_shape1.Name = "_shape1"
		_shape2.Height = 29
		_shape2.Left = 291
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 62
		Lb_titlu_alb_b121.Caption = "Sectia - comanda"
		Lb_titlu_alb_b121.Left = 11
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 5
		Lb_titlu_alb_b121.Top = 6
		BUT_TERMIN1.Left = 322
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 3
		BUT_TERMIN1.Top = 1
		Gridsort1.Left = 228
		Gridsort1.Name = "Gridsort1"
		Gridsort1.Top = 7
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 292, ;
		Name = "But_renunt1", ;
		TabIndex = 4, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_clb_comanda' AS ct_clb_cautare_var WITH ;
		cconditie = EMPTY(NVL(pnId_comanda,0)), ;
		cprocedura = thisform.do_cauta_comanda, ;
		cvar_afisata = pcNr_comanda, ;
		Height = 31, ;
		Left = 11, ;
		Name = "Ct_clb_comanda", ;
		TabIndex = 2, ;
		Top = 68, ;
		Width = 337, ;
		shape_cautare.Height = 29, ;
		shape_cautare.Left = 1, ;
		shape_cautare.Name = "shape_cautare", ;
		shape_cautare.Top = 1, ;
		shape_cautare.Width = 305, ;
		img_cautare.Left = 310, ;
		img_cautare.Name = "img_cautare", ;
		img_cautare.Top = 5, ;
		lb_cautare.Caption = "Comanda", ;
		lb_cautare.Name = "lb_cautare", ;
		tx_cautare.Left = 119, ;
		tx_cautare.Name = "tx_cautare", ;
		tx_cautare.Top = 4
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_clb_grup' AS ct_clb_cautare_var WITH ;
		cconditie = EMPTY(NVL(pnId_sectie,0)), ;
		cprocedura = thisform.do_cauta_sectie, ;
		cvar_afisata = pcSectie, ;
		Height = 31, ;
		Left = 11, ;
		Name = "Ct_clb_grup", ;
		TabIndex = 1, ;
		Top = 40, ;
		Width = 337, ;
		shape_cautare.Height = 29, ;
		shape_cautare.Left = 1, ;
		shape_cautare.Name = "shape_cautare", ;
		shape_cautare.Top = 1, ;
		shape_cautare.Width = 305, ;
		img_cautare.Left = 310, ;
		img_cautare.Name = "img_cautare", ;
		img_cautare.Top = 5, ;
		lb_cautare.Caption = "Sectia beneficiara", ;
		lb_cautare.Name = "lb_cautare", ;
		tx_cautare.Left = 119, ;
		tx_cautare.Name = "tx_cautare", ;
		tx_cautare.Top = 4
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />
	
	PROCEDURE do_cauta_comanda
		Local lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn , lcIdColumn, llModParam
		Store "" To loCauta
		
		lcSchema = []
		lcOrder = [nr_comanda]
		lccoloane = [nr_comanda,data_comanda]
		lcTitlu = [Alegeti comanda]
		lcTitluColoane = [Nr comanda,Data comanda]
		llMultipleArticles = .F.
		*!*	lcSelect = [select id_comanda,nr_comanda,data_comanda ] + ;
		*!*		[ from vcomenzi where id_sectie2= ] + ALLTRIM(STR(pnId_sectie))
		lcSelect = [select id_comanda,nr_comanda,data_comanda from vcomenzi ]
		lcFiltru = []
		lcFiltruOriginal = [data_livrat is null and inchisa = 0 and id_sectie2= ] + Alltrim(Str(pnId_sectie))
		lcNumeProc = []
		llToateIreg = .F.
		lcPrimaColoana = []
		lnPornire = 1
		lnTipReturn = Iif(llMultipleArticles, 1, 0)
		lcIdColumn = "id_comanda"
		llModParam = .F.
		
		loCauta = cauta_alfa(lcSelect, lcFiltru, lcSchema, lcOrder, lccoloane, lcTitlu, lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lcPrimaColoana, lnPornire, lnTipReturn , lcIdColumn,,,,,llModParam)		&& 11.07.2007
		***------------------------------
		If !Empty(Nvl(loCauta.id_comanda,0))
			pnId_comanda = loCauta.id_comanda
			pcNr_comanda = loCauta.nr_comanda
			Thisform.but_TERMIN1.SetFocus()
		Else
			pnId_comanda = 0
			pcNr_comanda = []
		Endif
		
	ENDPROC

	PROCEDURE do_cauta_sectie
		Local loCauta
		loCauta = caut_sectie()
		
		If !Empty(Nvl(loCauta.id_sectie,0))
			pnid_sectie = loCauta.id_sectie
			pcSectie = loCauta.sectie
		
			Thisform.ct_clb_comanda.SetFocus()
		Else
			pnid_sectie = Null
			pcSectie = []
		Endif
	ENDPROC

	PROCEDURE inainte_de_do_termin
		IF EMPTY(NVL(pnId_sectie,0))
			AMESSAGEBOX('Nu ati ales sectia!',48,"Atentie")
			THISFORM.CT_clb_grup.SetFocus()
			RETURN .F.
		ENDIF 
		
		IF EMPTY(NVL(pnId_comanda,0))
			AMESSAGEBOX('Nu ati ales comanda!',48,"Atentie")
			thisform.ct_clb_comanda.SetFocus()
			RETURN .F.
		ENDIF
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_conversie AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="_pgfrmbase1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.Clb_volum" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.Clb_densitate" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.Clb_masa" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.cb_um_volum" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.cb_um_masa_d" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.cb_um_volum_d" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.cb_um_masa" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.LB_SIMPLU1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.Clb_pret" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page1.Clb_prettr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page2.Clb_pret" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page2.Clb_pret_tr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page2.Clb_cantitate" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page2.cb_um" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page2.cb_um_orig" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_pgfrmbase1.Page2.Clb_cantitate_tr" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: do_actualizeaza_um
		*m: do_calculeaza_pret
		*m: do_conversie
		*p: calias
		*p: ccursor
		*p: cum
		*p: ncantitate
		*p: npret
		*p: ntip
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		calias = 
		ccursor = 
		cum = 
		DoCreate = .T.
		Height = 270
		Name = "frm_conversie"
		ncantitate = 0
		npret = 0
		ntip = 0
		Width = 480
		_memberdata = <VFPData>
			<memberdata name="ccursor" display="cCursor"/>
			<memberdata name="ntip" display="nTip"/>
		</VFPData>
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 480
		_shape2.Height = 29
		_shape2.Left = 443
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 39
		Lb_titlu_alb_b121.Caption = "Conversie"
		Lb_titlu_alb_b121.FontName = "Comic Sans MS"
		Lb_titlu_alb_b121.FontSize = 10
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 2
		BUT_TERMIN1.Left = 448
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 3
		BUT_TERMIN1.Top = 1
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT '_pgfrmbase1' AS _pgfrmbase WITH ;
		ErasePage = .T., ;
		Height = 215, ;
		Left = 14, ;
		Name = "_pgfrmbase1", ;
		PageCount = 2, ;
		TabIndex = 1, ;
		Top = 43, ;
		Width = 454, ;
		Page1.BackColor = 255,255,255, ;
		Page1.Caption = "\<Volum -> masa", ;
		Page1.Name = "Page1", ;
		Page1.PageOrder = 2, ;
		Page2.BackColor = 255,255,255, ;
		Page2.Caption = "\<Conversii", ;
		Page2.Name = "Page2", ;
		Page2.PageOrder = 1
		*< END OBJECT: ClassLib="_frm_base.vcx" BaseClass="pageframe" />

	ADD OBJECT '_pgfrmbase1.Page1.cb_um_masa' AS _cbbase WITH ;
		Height = 24, ;
		Left = 351, ;
		Name = "cb_um_masa", ;
		TabIndex = 6, ;
		Top = 121, ;
		Width = 60
		*< END OBJECT: ClassLib="_cb_base.vcx" BaseClass="combobox" />

	ADD OBJECT '_pgfrmbase1.Page1.cb_um_masa_d' AS _cbbase WITH ;
		Height = 24, ;
		Left = 325, ;
		Name = "cb_um_masa_d", ;
		TabIndex = 4, ;
		Top = 54, ;
		Width = 48
		*< END OBJECT: ClassLib="_cb_base.vcx" BaseClass="combobox" />

	ADD OBJECT '_pgfrmbase1.Page1.cb_um_volum' AS _cbbase WITH ;
		Height = 24, ;
		Left = 351, ;
		Name = "cb_um_volum", ;
		TabIndex = 2, ;
		Top = 26, ;
		Width = 60
		*< END OBJECT: ClassLib="_cb_base.vcx" BaseClass="combobox" />

	ADD OBJECT '_pgfrmbase1.Page1.cb_um_volum_d' AS _cbbase WITH ;
		Height = 24, ;
		Left = 390, ;
		Name = "cb_um_volum_d", ;
		TabIndex = 5, ;
		Top = 54, ;
		Width = 48
		*< END OBJECT: ClassLib="_cb_base.vcx" BaseClass="combobox" />

	ADD OBJECT '_pgfrmbase1.Page1.Clb_densitate' AS clb_tx_simplu WITH ;
		Left = 18, ;
		Name = "Clb_densitate", ;
		TabIndex = 3, ;
		Top = 52, ;
		TEXT_SIMPLU1.Alignment = 3, ;
		TEXT_SIMPLU1.Height = 23, ;
		TEXT_SIMPLU1.InputMask = "999 999.999", ;
		TEXT_SIMPLU1.Left = 131, ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.Top = 3, ;
		TEXT_SIMPLU1.Value = 0, ;
		TEXT_SIMPLU1.Width = 154, ;
		LB_SIMPLU1.Caption = "Densitate", ;
		LB_SIMPLU1.Name = "LB_SIMPLU1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page1.Clb_masa' AS clb_tx_simplu WITH ;
		Enabled = .F., ;
		Left = 18, ;
		Name = "Clb_masa", ;
		TabIndex = 8, ;
		Top = 119, ;
		TEXT_SIMPLU1.Alignment = 3, ;
		TEXT_SIMPLU1.Enabled = .F., ;
		TEXT_SIMPLU1.InputMask = "999 999 999.999", ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.Value = 0, ;
		LB_SIMPLU1.Caption = "Masa", ;
		LB_SIMPLU1.Name = "LB_SIMPLU1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page1.Clb_pret' AS clb_tx_simplu WITH ;
		Left = 18, ;
		Name = "Clb_pret", ;
		TabIndex = 7, ;
		Top = 80, ;
		Text_simplu1.Alignment = 3, ;
		Text_simplu1.ControlSource = "Thisform.npret", ;
		Text_simplu1.Height = 23, ;
		Text_simplu1.InputMask = (get_mask(12,gnPpret)), ;
		Text_simplu1.Left = 131, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Top = 3, ;
		Text_simplu1.Value = 0, ;
		Text_simplu1.Width = 154, ;
		Lb_simplu1.Caption = "Pret", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page1.Clb_prettr' AS clb_tx_simplu WITH ;
		Enabled = .F., ;
		Left = 18, ;
		Name = "Clb_prettr", ;
		TabIndex = 9, ;
		Top = 147, ;
		Text_simplu1.Alignment = 3, ;
		Text_simplu1.Enabled = .F., ;
		Text_simplu1.Format = "rK", ;
		Text_simplu1.InputMask = (get_mask(12,gnPpret)), ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Value = 0, ;
		Lb_simplu1.Caption = "Pret transformat", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page1.Clb_volum' AS clb_tx_simplu WITH ;
		Left = 18, ;
		Name = "Clb_volum", ;
		TabIndex = 1, ;
		Top = 24, ;
		TEXT_SIMPLU1.Alignment = 3, ;
		TEXT_SIMPLU1.InputMask = "999 999 999.999", ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.Value = 0, ;
		LB_SIMPLU1.Caption = "Volum", ;
		LB_SIMPLU1.Name = "LB_SIMPLU1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page1.LB_SIMPLU1' AS lb_simplu WITH ;
		Caption = "/", ;
		Left = 379, ;
		Name = "LB_SIMPLU1", ;
		TabIndex = 10, ;
		Top = 57
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT '_pgfrmbase1.Page2.cb_um' AS _cbbase WITH ;
		Height = 24, ;
		Left = 331, ;
		Name = "cb_um", ;
		TabIndex = 4, ;
		Top = 99, ;
		Width = 84
		*< END OBJECT: ClassLib="_cb_base.vcx" BaseClass="combobox" />

	ADD OBJECT '_pgfrmbase1.Page2.cb_um_orig' AS _cbbase WITH ;
		Height = 24, ;
		Left = 331, ;
		Name = "cb_um_orig", ;
		TabIndex = 2, ;
		Top = 26, ;
		Width = 84
		*< END OBJECT: ClassLib="_cb_base.vcx" BaseClass="combobox" />

	ADD OBJECT '_pgfrmbase1.Page2.Clb_cantitate' AS clb_tx_simplu WITH ;
		Left = 18, ;
		Name = "Clb_cantitate", ;
		TabIndex = 1, ;
		Top = 24, ;
		Text_simplu1.Alignment = 3, ;
		Text_simplu1.Height = 23, ;
		Text_simplu1.InputMask = (get_mask(14,gnPCant)), ;
		Text_simplu1.Left = 123, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Top = 3, ;
		Text_simplu1.Value = 0, ;
		Text_simplu1.Width = 162, ;
		Lb_simplu1.Caption = "Cantitate impach.", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page2.Clb_cantitate_tr' AS clb_tx_simplu WITH ;
		Enabled = .F., ;
		Left = 18, ;
		Name = "Clb_cantitate_tr", ;
		TabIndex = 6, ;
		Top = 97, ;
		Text_simplu1.Alignment = 3, ;
		Text_simplu1.Enabled = .F., ;
		Text_simplu1.InputMask = "999 999 999.999", ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Value = 0, ;
		Lb_simplu1.Caption = "Cantitate transf.", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page2.Clb_pret' AS clb_tx_simplu WITH ;
		Left = 18, ;
		Name = "Clb_pret", ;
		TabIndex = 3, ;
		Top = 52, ;
		Text_simplu1.Alignment = 3, ;
		Text_simplu1.ControlSource = "Thisform.npret", ;
		Text_simplu1.Height = 23, ;
		Text_simplu1.InputMask = (get_mask(12,gnPpret)), ;
		Text_simplu1.Left = 123, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Top = 3, ;
		Text_simplu1.Value = 0, ;
		Text_simplu1.Width = 162, ;
		Lb_simplu1.Caption = "Pret", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT '_pgfrmbase1.Page2.Clb_pret_tr' AS clb_tx_simplu WITH ;
		Enabled = .F., ;
		Left = 18, ;
		Name = "Clb_pret_tr", ;
		TabIndex = 5, ;
		Top = 125, ;
		Text_simplu1.Alignment = 3, ;
		Text_simplu1.Enabled = .F., ;
		Text_simplu1.Format = "rK", ;
		Text_simplu1.InputMask = (get_mask(12,gnPpret)), ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.Value = 0, ;
		Lb_simplu1.Caption = "Pret transformat", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />
	
	PROCEDURE Destroy
		If Used(This.cCursor)
			Use In (This.cCursor)
		Endif
		Select (This.cAlias)
		
	ENDPROC

	PROCEDURE do_actualizeaza_um
		Lparameters tcIdUm
		Local lnIdUm
		lnIdUm = Val(tcIdUm)
		Select (This.cCursor)
		Set Filter To
		Locate For id_um = lnIdUm
		If Found()
			lnTip = tip
		Else
			lnTip = 0
		Endif
		If This.nTip <> lnTip
			With Thisform._pgfrmbase1.page2.cb_um
				.Clear()
				.Refresh()
				This.nTip = lnTip
				Select (This.cCursor)
				Set Filter To tip = lnTip
				Scan
					.AddItem(um)
					.List[.NewIndex,2] = Alltrim(Str(id_um))
				Endscan
				.ListIndex = 1
			Endwith
		Endif
	ENDPROC

	PROCEDURE do_calculeaza_pret
		lnPaginaActiva = Thisform._pgfrmbase1.ActivePage
		With Thisform._pgfrmbase1
			Do Case
				Case lnPaginaActiva = 1
					With .page2
						lnCantitateTr = .clb_cantitate_tr.text_simplu1.Value
						lnPret = .clb_pret.text_simplu1.Value
						If lnCantitateTr <> 0
							lnPretTr = Round(lnPret / lnCantitateTr,gnPPret)
						Else
							lnPretTr = 0
						Endif
						.clb_pret_tr.text_simplu1.Value = lnPretTr
						.clb_pret_tr.text_simplu1.Refresh()
					Endwith
		*!*			Case lnPaginaActiva = 2
		*!*				With .page3
		*!*					lnCantitateTr = .clb_cantitate.text_simplu1.Value
		*!*					lnPret = .clb_pret.text_simplu1.Value
		*!*					If lnCantitateTr <> 0
		*!*						lnPretTr = Round(lnPret / lnCantitateTr,gnPPret)
		*!*					Else
		*!*						lnPretTr = 0
		*!*					Endif
		*!*					.clb_pret_tr.text_simplu1.Value = lnPretTr
		*!*					.clb_pret_tr.text_simplu1.Refresh()
		*!*				Endwith
				Case lnPaginaActiva = 2
					With .page1
						lnVolum=.clb_volum.text_simplu1.Value
						lnDensitate=.clb_densitate.text_simplu1.Value
						lnUmVolum=Val(.cb_um_volum.List[.cb_um_volum.listindex,2])
						lnUmVolumD=Val(.cb_um_volum_d.List[.cb_um_volum_d.listindex,2])
						lnUmMasaD=Val(.cb_um_masa_d.List[.cb_um_masa_d.listindex,2])
						lnUmMasa=Val(.cb_um_masa.List[.cb_um_masa.listindex,2])
						lnMasa=Round(lnVolum*lnUmVolum*lnDensitate*lnUmMasaD/(lnUmVolumD*lnUmMasa),3)
		
						.clb_masa.text_simplu1.Value=lnMasa
						.clb_masa.text_simplu1.Refresh()
		
						lnPret = .clb_pret.text_simplu1.Value
						lnValoare = lnPret * lnVolum
						lnPretTr = 0
						If lnMasa <> 0
							lnPretTr = Round(lnValoare/lnMasa,gnPPret)
						Endif
		
						.clb_prettr.text_simplu1.Value=lnPretTr
						.clb_prettr.text_simplu1.Refresh()
					Endwith
			Endcase
		Endwith
	ENDPROC

	PROCEDURE do_conversie
		lnPaginaActiva = Thisform._pgfrmbase1.ActivePage
		llDespachetare = .F.
		With Thisform._pgfrmbase1
			Do Case
				Case lnPaginaActiva = 1
					With .page2
						lnIdUM = Val(.cb_um_orig.List[.cb_um_orig.listindex,2])
						lnIdUM2 = Val(.cb_um.List[.cb_um.listindex,2])
						lnCantitate = .Clb_cantitate.text_simplu1.Value
						Select (This.cCursor)
						Set Filter To
						Locate For id_um = lnIdUM
						If Found()
							If tip <> -1
								llDespachetare = .T.
							Else
								lnCantitate = (Nvl(multiplicator,1) ^ Nvl(putere,1)) * lnCantitate
							Endif
						Else
							lnCantitate = 0
						Endif
						If !llDespachetare
							Locate For id_um = lnIdUM2
							If Found()
								lnCantitate = lnCantitate / (Nvl(multiplicator,1) ^ Nvl(putere,1))
							Else
								lnCantitate = 0
							Endif
						Endif
						.Clb_cantitate_tr.text_simplu1.Value = lnCantitate
						.Clb_cantitate_tr.text_simplu1.Refresh()
					Endwith
					Thisform.do_calculeaza_pret()
				Case lnPaginaActiva = 2
					With .page1
						lnVolum=.clb_volum.text_simplu1.Value
						lnDensitate=.clb_densitate.text_simplu1.Value
						lnUmVolum=Val(.cb_um_volum.List[.cb_um_volum.listindex,2])
						lnUmVolumD=Val(.cb_um_volum_d.List[.cb_um_volum_d.listindex,2])
						lnUmMasaD=Val(.cb_um_masa_d.List[.cb_um_masa_d.listindex,2])
						lnUmMasa=Val(.cb_um_masa.List[.cb_um_masa.listindex,2])
						lnMasa=Round(lnVolum*lnUmVolum*lnDensitate*lnUmMasaD/(lnUmVolumD*lnUmMasa),3)
						.clb_masa.text_simplu1.Value=lnMasa
						.clb_masa.text_simplu1.Refresh()
					Endwith
			Endcase
		Endwith
	ENDPROC

	PROCEDURE inainte_de_do_termin
		lnPaginaActiva = Thisform._pgfrmbase1.ActivePage
		With Thisform._pgfrmbase1
			Do Case
				Case lnPaginaActiva = 1
					pnTransformat = .page2.clb_cantitate_tr.text_simplu1.Value * Thisform.ncantitate
					pnPretTr = .page2.clb_pret_tr.text_simplu1.Value
		*!*			Case lnPaginaActiva = 2
		*!*				pnTransformat = .page3.clb_cantitate.text_simplu1.Value * Thisform.ncantitate
		*!*				pnPretTr = .page3.clb_pret_tr.text_simplu1.Value
				Case lnPaginaActiva = 2
					pnTransformat = .page1.clb_masa.text_simplu1.Value
					pnPretTr = .page1.clb_prettr.text_simplu1.Value
			Endcase
		Endwith
	ENDPROC

	PROCEDURE Init
		Lparameters tnPret,tcUm,tnCantitate	&&	,tnCantImpach
		DoDefault()
		Thisform.cum = UPPER(Alltrim(Nvl(tcUm,[])))
		Thisform.npret = tnPret
		Thisform.ncantitate = tnCantitate
		&&	Thisform._pgfrmbase1.page3.clb_cantitate.text_simplu1.Value = tnCantImpach
		
		This.cAlias = Alias()
		This.cCursor = Sys(2015)
		Create Cursor (This.cCursor) (id_um N(1),tip N(1),um c(100),multiplicator N(10,4) Null,putere N(2) Null,id_um_fund N(1) Null)
		Insert Into (This.cCursor) (id_um,tip,um,multiplicator,putere,id_um_fund) ;
			VALUES (1,-1,'BUC',Null,Null,Null)
		Insert Into (This.cCursor) (id_um,tip,um,multiplicator,putere,id_um_fund) ;
			VALUES (2,1,'KG',Null,Null,Null)
		Insert Into (This.cCursor) (id_um,tip,um,multiplicator,putere,id_um_fund) ;
			VALUES (3,1,'G',10,-3,2)
		Insert Into (This.cCursor) (id_um,tip,um,multiplicator,putere,id_um_fund) ;
			VALUES (4,1,'T',10,3,2)
		Insert Into (This.cCursor) (id_um,tip,um,multiplicator,putere,id_um_fund) ;
			VALUES (5,2,'L',Null,Null,Null)
		Insert Into (This.cCursor) (id_um,tip,um,multiplicator,putere,id_um_fund) ;
			VALUES (6,2,'ML',10,-3,5)
		Insert Into (This.cCursor) (id_um,tip,um,multiplicator,putere,id_um_fund) ;
			VALUES (7,2,'CL',10,-2,5)
		
		Select (This.cCursor)
		Locate For um = This.cum
		If Found()
			lnTip = tip
			This.nTip = lnTip
			With Thisform._pgfrmbase1.page2.Cb_um
				.AddItem(This.cum)
				.List[.NewIndex,2] = Alltrim(Str(id_um))
				.ListIndex = 1
			Endwith
		
			Select (This.cCursor)
			Set Filter To tip = lnTip
		Else
			This.nTip = 0
		Endif
		Select (This.cCursor)
		With Thisform._pgfrmbase1.page2.cb_um_orig
			Scan
				.AddItem(um)
				.List[.NewIndex,2] = Alltrim(Str(id_um))
			Endscan
			.ListIndex = 1
		Endwith
		Thisform._pgfrmbase1.page2.Clb_cantitate.SetFocus()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_masa.Init
		This.AddItem([g])
		This.List[1,2]=[0.001]
		This.AddItem([kg])
		This.List[2,2]=[1]
		This.ListIndex=1
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_masa.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_masa_d.Init
		This.AddItem([g])
		This.List[1,2]=[0.001]
		This.AddItem([kg])
		This.List[2,2]=[1]
		This.ListIndex=2
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_masa_d.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_volum.Init
		This.AddItem([l])
		This.List[1,2]=[0.001]
		This.AddItem([cl])
		This.List[2,2]=[0.00001]
		This.AddItem([ml])
		This.List[3,2]=[0.000001]
		This.AddItem([m^3])
		This.List[4,2]=[1]
		This.ListIndex=1
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_volum.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_volum_d.Init
		This.AddItem([l])
		This.List[1,2]=[0.001]
		This.AddItem([cl])
		This.List[2,2]=[0.00001]
		This.AddItem([ml])
		This.List[3,2]=[0.000001]
		This.AddItem([m^3])
		This.List[4,2]=[1]
		This.ListIndex=4
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.cb_um_volum_d.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.Clb_densitate.TEXT_SIMPLU1.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.Clb_pret.Text_simplu1.InteractiveChange
		Thisform.do_calculeaza_pret()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.Clb_pret.Text_simplu1.Valid
		Thisform.do_calculeaza_pret()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page1.Clb_volum.TEXT_SIMPLU1.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page2.cb_um.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page2.cb_um_orig.InteractiveChange
		Thisform.do_actualizeaza_um(This.List[This.ListIndex,2])
		Thisform.do_conversie()
		
	ENDPROC

	PROCEDURE _pgfrmbase1.Page2.Clb_cantitate.Text_simplu1.InteractiveChange
		Thisform.do_conversie()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page2.Clb_pret.Text_simplu1.InteractiveChange
		Thisform.do_calculeaza_pret()
	ENDPROC

	PROCEDURE _pgfrmbase1.Page2.Clb_pret.Text_simplu1.Valid
		Thisform.do_calculeaza_pret()
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_introd8039 AS frm_introdnir OF "ointroduceri.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Shape3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Shape2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Shape1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item12" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item13" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ItemGradUzura" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item14" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*p: nprocentuzura
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		DoCreate = .T.
		Height = 354
		Name = "frm_introd8039"
		nprocentuzura = 0
		Width = 670
		Item2.Label_item1.Name = "Label_item1"
		Item2.Left = 17
		Item2.Lineo1.Name = "Lineo1"
		Item2.Lineo2.Name = "Lineo2"
		Item2.Lineo3.Name = "Lineo3"
		Item2.Lineo4.Name = "Lineo4"
		Item2.Lineo5.Name = "Lineo5"
		Item2.Name = "Item2"
		Item2.TabIndex = 2
		Item2.Text_item1.Name = "Text_item1"
		Item2.Top = 87
		Item2.ZOrderSet = 3
		Item14.Label_item1.Name = "Label_item1"
		Item14.Lineo1.Name = "Lineo1"
		Item14.Lineo2.Name = "Lineo2"
		Item14.Lineo3.Name = "Lineo3"
		Item14.Lineo4.Name = "Lineo4"
		Item14.Lineo5.Name = "Lineo5"
		Item14.Name = "Item14"
		Item14.Text_item1.Name = "Text_item1"
		Item14.Text_item2.Name = "Text_item2"
		Item13.Label_item1.Name = "Label_item1"
		Item13.Left = 17
		Item13.Lineo1.Name = "Lineo1"
		Item13.Lineo2.Name = "Lineo2"
		Item13.Lineo3.Name = "Lineo3"
		Item13.Lineo4.Name = "Lineo4"
		Item13.Lineo5.Name = "Lineo5"
		Item13.Name = "Item13"
		Item13.Text_item1.Name = "Text_item1"
		Item13.Top = 40
		Item1.Label_item1.Name = "Label_item1"
		Item1.Left = 17
		Item1.Lineo1.Name = "Lineo1"
		Item1.Lineo2.Name = "Lineo2"
		Item1.Lineo3.Name = "Lineo3"
		Item1.Lineo4.Name = "Lineo4"
		Item1.Lineo5.Name = "Lineo5"
		Item1.Name = "Item1"
		Item1.TabIndex = 1
		Item1.Text_item1.Name = "Text_item1"
		Item1.Top = 64
		Item1.ZOrderSet = 6
		Item15.Label_item1.Name = "Label_item1"
		Item15.Lineo1.Name = "Lineo1"
		Item15.Lineo2.Name = "Lineo2"
		Item15.Lineo3.Name = "Lineo3"
		Item15.Lineo4.Name = "Lineo4"
		Item15.Lineo5.Name = "Lineo5"
		Item15.Name = "Item15"
		Item15.Text_item1.Name = "Text_item1"
		Item16.Label_item1.Name = "Label_item1"
		Item16.Lineo1.Name = "Lineo1"
		Item16.Lineo2.Name = "Lineo2"
		Item16.Lineo3.Name = "Lineo3"
		Item16.Lineo4.Name = "Lineo4"
		Item16.Lineo5.Name = "Lineo5"
		Item16.Name = "Item16"
		Item16.Text_item1.Name = "Text_item1"
		But_renunt1.Left = 570
		But_renunt1.Name = "But_renunt1"
		But_renunt1.TabIndex = 13
		But_renunt1.Top = 1
		But_renunt1.ZOrderSet = 11
		Item3.Label_item1.Name = "Label_item1"
		Item3.Left = 17
		Item3.Lineo1.Name = "Lineo1"
		Item3.Lineo2.Name = "Lineo2"
		Item3.Lineo3.Name = "Lineo3"
		Item3.Lineo4.Name = "Lineo4"
		Item3.Lineo5.Name = "Lineo5"
		Item3.Name = "Item3"
		Item3.TabIndex = 3
		Item3.Text_item1.Name = "Text_item1"
		Item3.Top = 111
		Item3.ZOrderSet = 12
		Item4.Label_item1.Name = "Label_item1"
		Item4.Left = 17
		Item4.Lineo1.Name = "Lineo1"
		Item4.Lineo2.Name = "Lineo2"
		Item4.Lineo3.Name = "Lineo3"
		Item4.Lineo4.Name = "Lineo4"
		Item4.Lineo5.Name = "Lineo5"
		Item4.Name = "Item4"
		Item4.TabIndex = 4
		Item4.Text_item1.Name = "Text_item1"
		Item4.Top = 135
		Item4.ZOrderSet = 13
		Item5.Label_item1.Name = "Label_item1"
		Item5.Left = 17
		Item5.Lineo1.Name = "Lineo1"
		Item5.Lineo2.Name = "Lineo2"
		Item5.Lineo3.Name = "Lineo3"
		Item5.Lineo4.Name = "Lineo4"
		Item5.Lineo5.Name = "Lineo5"
		Item5.Name = "Item5"
		Item5.TabIndex = 5
		Item5.Text_item1.Name = "Text_item1"
		Item5.Top = 159
		Item5.ZOrderSet = 14
		Item6.Label_item1.Name = "Label_item1"
		Item6.Left = 16
		Item6.Lineo1.Name = "Lineo1"
		Item6.Lineo2.Name = "Lineo2"
		Item6.Lineo3.Name = "Lineo3"
		Item6.Lineo4.Name = "Lineo4"
		Item6.Lineo5.Name = "Lineo5"
		Item6.Name = "Item6"
		Item6.TabIndex = 14
		Item6.Text_item1.Name = "Text_item1"
		Item6.Top = 357
		Item6.ZOrderSet = 15
		Item7.Comment = ""
		Item7.Label_item1.Name = "Label_item1"
		Item7.Left = 14
		Item7.Lineo1.Name = "Lineo1"
		Item7.Lineo2.Name = "Lineo2"
		Item7.Lineo3.Name = "Lineo3"
		Item7.Lineo4.Name = "Lineo4"
		Item7.Lineo5.Name = "Lineo5"
		Item7.Name = "Item7"
		Item7.TabIndex = 16
		Item7.Text_item1.Name = "Text_item1"
		Item7.Top = 377
		Item7.Visible = .F.
		Item7.ZOrderSet = 16
		Item8.Comment = ""
		Item8.Label_item1.Name = "Label_item1"
		Item8.Left = 14
		Item8.Lineo1.Name = "Lineo1"
		Item8.Lineo2.Name = "Lineo2"
		Item8.Lineo3.Name = "Lineo3"
		Item8.Lineo4.Name = "Lineo4"
		Item8.Lineo5.Name = "Lineo5"
		Item8.Name = "Item8"
		Item8.TabIndex = 17
		Item8.Text_item1.Name = "Text_item1"
		Item8.Top = 400
		Item8.Visible = .F.
		Item8.ZOrderSet = 17
		Item9.Comment = ""
		Item9.Label_item1.Name = "Label_item1"
		Item9.Left = 14
		Item9.Lineo1.Name = "Lineo1"
		Item9.Lineo2.Name = "Lineo2"
		Item9.Lineo3.Name = "Lineo3"
		Item9.Lineo4.Name = "Lineo4"
		Item9.Lineo5.Name = "Lineo5"
		Item9.Name = "Item9"
		Item9.TabIndex = 18
		Item9.Text_item1.Name = "Text_item1"
		Item9.Top = 423
		Item9.Visible = .F.
		Item9.ZOrderSet = 18
		Item17.Label_item1.Name = "Label_item1"
		Item17.Left = 17
		Item17.Lineo1.Name = "Lineo1"
		Item17.Lineo2.Name = "Lineo2"
		Item17.Lineo3.Name = "Lineo3"
		Item17.Lineo4.Name = "Lineo4"
		Item17.Lineo5.Name = "Lineo5"
		Item17.Name = "Item17"
		Item17.Text_item1.Name = "Text_item1"
		Item17.Top = 324
		Item12.Label_item1.Name = "Label_item1"
		Item12.Left = 5
		Item12.Lineo1.Name = "Lineo1"
		Item12.Lineo2.Name = "Lineo2"
		Item12.Lineo3.Name = "Lineo3"
		Item12.Lineo4.Name = "Lineo4"
		Item12.Lineo5.Name = "Lineo5"
		Item12.Name = "Item12"
		Item12.Text_item1.Name = "Text_item1"
		Item12.Top = 230
		Item10.camp_lista = nume
		Item10.Comment = "B"
		Item10.fis_lista = Vnom_responsabili    
		Item10.id_fisier = id_responsabil
		Item10.label_item = Nume responsabil
		Item10.Label_item1.Caption = "Responsabil"
		Item10.Label_item1.Name = "Label_item1"
		Item10.Left = 17
		Item10.Lineo1.Name = "Lineo1"
		Item10.Lineo2.Name = "Lineo2"
		Item10.Lineo3.Name = "Lineo3"
		Item10.Lineo4.Name = "Lineo4"
		Item10.Lineo5.Name = "Lineo5"
		Item10.Name = "Item10"
		Item10.TabIndex = 11
		Item10.TabStop = .T.
		Item10.Text_item1.Comment = "thisform.cobj.nresp"
		Item10.Text_item1.Name = "Text_item1"
		Item10.Text_item1.ReadOnly = .T.
		Item10.Top = 299
		Item10.ZOrderSet = 20
		Item11.Label_item1.Name = "Label_item1"
		Item11.Left = 17
		Item11.Lineo1.Name = "Lineo1"
		Item11.Lineo2.Name = "Lineo2"
		Item11.Lineo3.Name = "Lineo3"
		Item11.Lineo4.Name = "Lineo4"
		Item11.Lineo5.Name = "Lineo5"
		Item11.Name = "Item11"
		Item11.TabIndex = 10
		Item11.TabStop = .F.
		Item11.Text_item1.Name = "Text_item1"
		Item11.Text_item1.ReadOnly = .T.
		Item11.Top = 324
		Item11.ZOrderSet = 19
		lb_modparam.Left = 486
		lb_modparam.Name = "lb_modparam"
		lb_modparam.Top = 139
		_shape1.Name = "_shape1"
		_shape1.ZOrderSet = 7
		_shape2.Name = "_shape2"
		_shape2.ZOrderSet = 8
		Gridsort1.Left = 1
		Gridsort1.Name = "Gridsort1"
		Gridsort1.Top = 42
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 19
		Lb_titlu_alb_b121.ZOrderSet = 10
		BUT_TERMIN1.Left = 639
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 12
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 25
		Clb_ITEM_adaos.Comment = ""
		Clb_ITEM_adaos.Lb_simplu1.Name = "Lb_simplu1"
		Clb_ITEM_adaos.Left = 472
		Clb_ITEM_adaos.Name = "Clb_ITEM_adaos"
		Clb_ITEM_adaos.TabIndex = 15
		Clb_ITEM_adaos.Text_simplu1.Name = "Text_simplu1"
		Clb_ITEM_adaos.Top = 379
		Clb_ITEM_adaos.Visible = .F.
		Clb_ITEM_adaos.ZOrderSet = 26
		But_modiparam1.Left = 492
		But_modiparam1.Name = "But_modiparam1"
		But_modiparam1.Top = 156
		Image1.Height = 16
		Image1.Left = 461
		Image1.Name = "Image1"
		Image1.Top = 232
		Image1.Width = 16
		Opt_imputare.Left = 483
		Opt_imputare.Name = "Opt_imputare"
		Opt_imputare.Option1.Left = 5
		Opt_imputare.Option1.Name = "Option1"
		Opt_imputare.Option1.Top = 5
		Opt_imputare.Option2.Left = 5
		Opt_imputare.Option2.Name = "Option2"
		Opt_imputare.Option2.Top = 20
		Opt_imputare.Top = 265
		lb_imputare.Left = 489
		lb_imputare.Name = "lb_imputare"
		lb_imputare.Top = 255
		cbo_tva_achizitie.Left = 480
		cbo_tva_achizitie.Name = "cbo_tva_achizitie"
		cbo_tva_achizitie.Top = 112
		lb_tva_achizitie.Name = "lb_tva_achizitie"
		cbo_tva_vanzare.Left = 475
		cbo_tva_vanzare.Name = "cbo_tva_vanzare"
		cbo_tva_vanzare.Top = 371
		lb_tva_vanzare.Left = 480
		lb_tva_vanzare.Name = "lb_tva_vanzare"
		lb_tva_vanzare.Top = 354
		But_renunt2.Name = "But_renunt2"
		cmdTVA1.Name = "cmdTVA1"
		cmdTVA2.Name = "cmdTVA2"
		cmdTVA3.Name = "cmdTVA3"
		cmdTVA4.Name = "cmdTVA4"
		cmdTVA5.Name = "cmdTVA5"
		cbo_saft.Name = "cbo_saft"
		lb_saft.Name = "lb_saft"
	*</PropValue>

	ADD OBJECT 'Item12' AS item WITH ;
		Comment = "T", ;
		Left = 17, ;
		Name = "Item12", ;
		TabIndex = 9, ;
		tip = F, ;
		Top = 265, ;
		ZOrderSet = 4, ;
		Label_item1.Caption = "Durata de folosinta ramasa(luni)", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.DNS_LUNI", ;
		Text_item1.InputMask = (get_mask(4,0)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item13' AS item WITH ;
		Comment = "T", ;
		Left = 17, ;
		Name = "Item13", ;
		TabIndex = 6, ;
		tip = F, ;
		Top = 198, ;
		ZOrderSet = 5, ;
		Label_item1.Caption = "Data trecerii in folosinta", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Alignment = 3, ;
		Text_item1.Comment = "thisform.cobj.DATAPIF", ;
		Text_item1.Format = "k", ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item14' AS item WITH ;
		Comment = "T", ;
		Left = 17, ;
		Name = "Item14", ;
		TabIndex = 8, ;
		tip = F, ;
		Top = 243, ;
		ZOrderSet = 27, ;
		Label_item1.Caption = "Durata normata de folosinta", ;
		Label_item1.Name = "Label_item1", ;
		Label_item1.TabIndex = 2, ;
		Text_item1.Comment = "thisform.cobj.DNF", ;
		Text_item1.InputMask = (get_mask(3,0)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Text_item1.TabIndex = 1, ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'ItemGradUzura' AS item WITH ;
		Comment = "T", ;
		Left = 17, ;
		Name = "ItemGradUzura", ;
		TabIndex = 7, ;
		tip = F, ;
		Top = 220, ;
		ZOrderSet = 27, ;
		LABEL_ITEM1.Caption = "Grad uzura (%)", ;
		LABEL_ITEM1.Name = "LABEL_ITEM1", ;
		LABEL_ITEM1.TabIndex = 2, ;
		TEXT_ITEM1.Comment = "thisform.nProcentUzura", ;
		TEXT_ITEM1.ControlSource = "thisform.nProcentUzura", ;
		TEXT_ITEM1.InputMask = (get_mask(3,0)), ;
		TEXT_ITEM1.Name = "TEXT_ITEM1", ;
		TEXT_ITEM1.TabIndex = 1, ;
		LINEO1.Name = "LINEO1", ;
		LINEO3.Name = "LINEO3", ;
		LINEO4.Name = "LINEO4", ;
		LINEO5.Name = "LINEO5", ;
		LINEO2.Name = "LINEO2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Shape1' AS shape WITH ;
		BackColor = 255,255,255, ;
		BorderColor = 128,128,128, ;
		Height = 154, ;
		Left = 13, ;
		Name = "Shape1", ;
		Top = 38, ;
		Width = 464, ;
		ZOrderSet = 2
		*< END OBJECT: BaseClass="shape" />

	ADD OBJECT 'Shape2' AS shape WITH ;
		BackColor = 255,255,255, ;
		BorderColor = 128,128,128, ;
		Height = 101, ;
		Left = 13, ;
		Name = "Shape2", ;
		Top = 190, ;
		Width = 464, ;
		ZOrderSet = 1
		*< END OBJECT: BaseClass="shape" />

	ADD OBJECT 'Shape3' AS shape WITH ;
		BackColor = 255,255,255, ;
		BorderColor = 128,128,128, ;
		Height = 60, ;
		Left = 13, ;
		Name = "Shape3", ;
		Top = 290, ;
		Width = 464, ;
		ZOrderSet = 0
		*< END OBJECT: BaseClass="shape" />
	
	PROCEDURE Show
		Lparameters nStyle
		
		thisform.cobj.DATAPIF = thisform.cobj.DATAACT
		
		lnDNF = thisform.cobj.DNF
		IF thisform.cobj.DNS_LUNI = 0
			thisform.cobj.DNS_LUNI = thisform.cobj.DNF
		ENDIF 
		
		lnDNSRamas = thisform.cobj.DNS_LUNI
		IF lnDNF = 0
			THISFORM.nProcentuzura = 0
		ELSE
			THISFORM.nProcentuzura = ROUND((lnDNF - lnDNSRamas)/lnDNF*100,0)
		ENDIF 
		this.itemgradUzura.text_item1.ControlSource = "thisform.nProcentUzura"
		
		DODEFAULT(nStyle)
	ENDPROC

	PROCEDURE Item12.Text_item1.Valid
		DODEFAULT()
		lnDNF = thisform.cobj.DNF
		lnDNSRamas = thisform.cobj.DNS_LUNI
		IF lnDNF = 0
			THISFORM.nProcentuzura = 0
		ELSE
			THISFORM.nProcentuzura = ROUND((lnDNF - lnDNSRamas)/lnDNF*100,0)
		ENDIF 
		thisform.Refresh 
	ENDPROC

	PROCEDURE Item14.Init
		IF INLIST(oset.id_set, 55, 273) && dare in folosinta
			this.tEXT_ITEM1.ReadOnly = .f.
		ENDIF 
	ENDPROC

	PROCEDURE ItemGradUzura.TEXT_ITEM1.Valid
		DODEFAULT()
		thisform.cobj.DNS_LUNI = ROUND(thisform.cobj.DNF*(100 - thisform.nprocentuzura)/100,0)
		thisform.Refresh()
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_introdnir AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Item2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item14" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item14.Text_item2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item13" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item15" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item16" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item4" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item5" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item6" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item7" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item8" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item9" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item17" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item12" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item10" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item11" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_modparam" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_ITEM_adaos" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_modiparam1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Image1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Opt_imputare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_imputare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cbo_tva_achizitie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_tva_achizitie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cbo_tva_vanzare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_tva_vanzare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdTVA1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdTVA2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdTVA3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdTVA4" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdTVA5" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cbo_saft" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_saft" UniqueID="" Timestamp="" />

	#INCLUDE "..\include\foxpro.h"
	*<DefinedPropArrayMethod>
		*m: actualizeaza_explicatie_saft
		*m: aplicatva
		*m: calculeaza_tva_ach
		*m: calculeaza_valori_ach
		*m: do_alege_reteta
		*m: do_alege_tvaach
		*m: do_alege_tvavanz
		*m: do_modiparam
		*m: updateexplicatiesaft
		*m: updatelabelsaft
		*m: updatepaymentsaft
		*p: blochezpretv
		*p: cobj
		*p: cparentobj
		*p: cpaymentcode		&& Cod Taxa SAFT
		*p: ctitlu
		*p: lmonedanationala		&& .T. - daca id_valuta este moneda nationala
		*p: ncant_iesita
		*p: ncant_stoc
		*p: ncurs
		*p: npretvoriginal
		*p: npretv_nat
		*p: npretv_val
		*p: npret_nat
		*p: npret_val
		*p: ntaxcodeachizitie		&& Cod taxa SAFT achizitie
		*p: ntaxcodevanzare		&& Cod taxa SAFT vanzare
		*p: omemopref		&& Obiect in care se memoreaza datele care sa fie folosite ca implicite cand se apeleaza formularul.
		*p: pretu_factura
		*p: pretvtva
		*p: proc_adaos
		*p: proc_discount
		*p: proc_tvav
		*p: valoare
		*p: valoaretva
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		bvizualizare = 
		cobj = 
		cpaymentcode = 
		ctitlu = 
		DoCreate = .T.
		FontCharSet = 238
		Height = 466
		lmonedanationala = .T.
		Name = "frm_introdnir"
		ncant_iesita = .F.
		ncant_stoc = .F.
		ncurs = 0
		npretvoriginal = 0
		npretv_nat = 0
		npretv_val = 0
		npret_nat = 0
		npret_val = 0
		ntaxcodeachizitie = NULL
		ntaxcodevanzare = NULL
		omemopref = .NULL.
		pretu_factura = 0
		pretvtva = 0
		proc_adaos = 0
		proc_discount = 0
		proc_tvav = 0
		valoare = 0
		valoaretva = 0
		Width = 670
		WindowType = 1
		_memberdata = <VFPData>
			<memberdata name="aplicatva" display="AplicaTVA"/>
			<memberdata name="updatepaymentsaft" display="UpdatePaymentSAFT"/>
			<memberdata name="cpaymentcode" display="cPaymentCode"/>
			<memberdata name="updateexplicatiesaft" display="UpdateExplicatieSAFT"/>
			<memberdata name="ntaxcodeachizitie" display="nTaxCodeAchizitie"/>
			<memberdata name="ntaxcodevanzare" display="nTaxCodeVanzare"/>
			<memberdata name="updatelabelsaft" display="UpdateLabelSaft"/>
		</VFPData>
		_shape1.Height = 30
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = -1
		_shape1.Width = 676
		_shape1.ZOrderSet = 2
		_shape2.Height = 29
		_shape2.Left = 601
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 70
		_shape2.ZOrderSet = 3
		Lb_titlu_alb_b121.FontName = "Comic Sans MS"
		Lb_titlu_alb_b121.FontSize = 10
		Lb_titlu_alb_b121.Left = 8
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 21
		Lb_titlu_alb_b121.Top = 4
		Lb_titlu_alb_b121.ZOrderSet = 4
		BUT_TERMIN1.Left = 640
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 17
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 5
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'But_modiparam1' AS but_modiparam WITH ;
		Left = 532, ;
		Name = "But_modiparam1", ;
		TabIndex = 22, ;
		TabStop = .F., ;
		ToolTipText = "Conversie", ;
		Top = 233
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 571, ;
		Name = "But_renunt1", ;
		TabIndex = 18, ;
		Top = 1, ;
		ZOrderSet = 6
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_renunt2' AS but_renunt WITH ;
		Left = 608, ;
		Name = "But_renunt2", ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cbo_saft' AS combobox WITH ;
		BorderColor = 128,128,128, ;
		BorderStyle = 1, ;
		ColumnLines = .F., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Height = 20, ;
		InputMask = "", ;
		Left = 475, ;
		Name = "cbo_saft", ;
		RowSourceType = 3, ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 27, ;
		TabStop = .F., ;
		Top = 207, ;
		Visible = .F., ;
		Width = 190
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'cbo_tva_achizitie' AS _combobox WITH ;
		BorderColor = 128,128,128, ;
		BorderStyle = 1, ;
		Comment = "F", ;
		ControlSource = "", ;
		FontSize = 10, ;
		Height = 24, ;
		InputMask = "", ;
		Left = 475, ;
		Name = "cbo_tva_achizitie", ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 28, ;
		TabStop = .F., ;
		Top = 164, ;
		Visible = .T., ;
		Width = 190
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="combobox" />

	ADD OBJECT 'cbo_tva_vanzare' AS _combobox WITH ;
		BorderColor = 128,128,128, ;
		BorderStyle = 1, ;
		Comment = "A", ;
		ControlSource = "", ;
		Left = 475, ;
		Name = "cbo_tva_vanzare", ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 27, ;
		TabStop = .F., ;
		Top = 378, ;
		Visible = .T., ;
		Width = 190
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="combobox" />

	ADD OBJECT 'Clb_ITEM_adaos' AS clb_tx_simplu WITH ;
		BorderColor = 255,255,255, ;
		Comment = "A", ;
		Height = 23, ;
		Left = 472, ;
		Name = "Clb_ITEM_adaos", ;
		TabIndex = 13, ;
		Top = 333, ;
		Width = 77, ;
		TEXT_SIMPLU1.Alignment = 1, ;
		TEXT_SIMPLU1.BackColor = 224,224,224, ;
		TEXT_SIMPLU1.BorderStyle = 0, ;
		TEXT_SIMPLU1.Comment = "thisform.cobj.procent", ;
		TEXT_SIMPLU1.Height = 23, ;
		TEXT_SIMPLU1.InputMask = (get_mask(12,2)), ;
		TEXT_SIMPLU1.Left = 2, ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.SpecialEffect = 1, ;
		TEXT_SIMPLU1.Top = 2, ;
		TEXT_SIMPLU1.Width = 53, ;
		LB_SIMPLU1.Caption = "%", ;
		LB_SIMPLU1.Left = 61, ;
		LB_SIMPLU1.Name = "LB_SIMPLU1", ;
		LB_SIMPLU1.Top = 5
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'cmdTVA1' AS cmd_executa WITH ;
		Caption = "19%", ;
		Left = 471, ;
		Name = "cmdTVA1", ;
		Top = 115, ;
		Visible = .F., ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdTVA2' AS cmd_executa WITH ;
		Caption = "9%", ;
		Left = 501, ;
		Name = "cmdTVA2", ;
		Top = 115, ;
		Visible = .F., ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdTVA3' AS cmd_executa WITH ;
		Caption = "5%", ;
		Left = 531, ;
		Name = "cmdTVA3", ;
		Top = 115, ;
		Visible = .F., ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdTVA4' AS cmd_executa WITH ;
		Caption = "5%", ;
		Left = 561, ;
		Name = "cmdTVA4", ;
		Top = 115, ;
		Visible = .F., ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdTVA5' AS cmd_executa WITH ;
		Caption = "5%", ;
		Left = 591, ;
		Name = "cmdTVA5", ;
		Top = 115, ;
		Visible = .F., ;
		Width = 30
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Image1' AS image WITH ;
		Height = 16, ;
		Left = 472, ;
		Name = "Image1", ;
		Picture = ..\grafice\alege.bmp, ;
		ToolTipText = "Alege fisa tehnologica alternativa (R)", ;
		Top = 263, ;
		Width = 16
		*< END OBJECT: BaseClass="image" />

	ADD OBJECT 'Item1' AS item WITH ;
		Comment = "F", ;
		Left = 14, ;
		Name = "Item1", ;
		TabIndex = 4, ;
		tip = F, ;
		Top = 117, ;
		ZOrderSet = 1, ;
		Label_item1.Caption = "Pret unitar pe factura", ;
		Label_item1.FontCharSet = 238, ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.pretu_factura", ;
		Text_item1.InputMask = (get_mask(12,gnPpret)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item10' AS item WITH ;
		camp_lista = nume_gestiune,cgest, ;
		Comment = "N", ;
		fis_lista = Vnom_gestiuni       , ;
		id_fisier = id_gestiune, ;
		label_item = Nume gestiune destinatie, ;
		Left = 14, ;
		Name = "Item10", ;
		pcobj = orul, ;
		TabIndex = 11, ;
		TabStop = .F., ;
		tip = N, ;
		Top = 286, ;
		ZOrderSet = 14, ;
		Label_item1.Caption = "Gestiunea", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.gestin", ;
		Text_item1.ControlSource = "", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item11' AS item WITH ;
		camp_lista = sectie, ;
		Comment = "T", ;
		fis_lista = Vnom_sectii, ;
		id_fisier = id_sectie, ;
		label_item = Denumire sectie, ;
		Left = 14, ;
		Name = "Item11", ;
		pcobj = orul, ;
		TabIndex = 12, ;
		TabStop = .F., ;
		tip = , ;
		Top = 309, ;
		ZOrderSet = 14, ;
		Label_item1.Caption = "Sectia", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.sectie", ;
		Text_item1.ControlSource = "", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item12' AS item WITH ;
		camp_lista = reteta, ;
		Comment = "N", ;
		fis_lista = , ;
		id_fisier = id_reteta, ;
		label_item = Fisa tehnologica, ;
		Left = 13, ;
		Name = "Item12", ;
		pcobj = orul, ;
		TabIndex = 10, ;
		TabStop = .T., ;
		tip = N, ;
		Top = 261, ;
		ZOrderSet = 14, ;
		Label_item1.Caption = "Fiºa tehnologica", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.reteta", ;
		Text_item1.ControlSource = "", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item13' AS item WITH ;
		Comment = "T", ;
		Left = 14, ;
		Name = "Item13", ;
		TabIndex = 1, ;
		tip = T, ;
		Top = 40, ;
		ZOrderSet = 1, ;
		Label_item1.Caption = "Serie", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.serie", ;
		Text_item1.Format = "K!", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item14' AS item WITH ;
		Comment = "T", ;
		Height = 21, ;
		Left = 478, ;
		Name = "Item14", ;
		TabIndex = 19, ;
		TabStop = .F., ;
		tip = T, ;
		Top = 40, ;
		Width = 136, ;
		ZOrderSet = 1, ;
		LABEL_ITEM1.Caption = "Cont", ;
		LABEL_ITEM1.Height = 18, ;
		LABEL_ITEM1.Left = 3, ;
		LABEL_ITEM1.Name = "LABEL_ITEM1", ;
		LABEL_ITEM1.Top = 2, ;
		LABEL_ITEM1.Width = 45, ;
		TEXT_ITEM1.Comment = "thisform.cobj.cont", ;
		TEXT_ITEM1.Format = "K!", ;
		TEXT_ITEM1.Height = 18, ;
		TEXT_ITEM1.Left = 52, ;
		TEXT_ITEM1.MaxLength = 4, ;
		TEXT_ITEM1.Name = "TEXT_ITEM1", ;
		TEXT_ITEM1.ReadOnly = .T., ;
		TEXT_ITEM1.Top = 1, ;
		TEXT_ITEM1.Width = 35, ;
		LINEO1.Name = "LINEO1", ;
		LINEO3.Name = "LINEO3", ;
		LINEO4.Name = "LINEO4", ;
		LINEO5.Name = "LINEO5", ;
		LINEO2.Name = "LINEO2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item14.Text_item2' AS text_item WITH ;
		BackStyle = 1, ;
		BorderColor = 226,226,226, ;
		BorderStyle = 1, ;
		Comment = "thisform.cobj.acont", ;
		FontName = "Arial", ;
		Format = "K!", ;
		Height = 18, ;
		Left = 92, ;
		MaxLength = 4, ;
		Name = "Text_item2", ;
		ReadOnly = .T., ;
		Top = 1, ;
		Width = 35
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'Item15' AS item WITH ;
		Comment = "T", ;
		Left = 14, ;
		Name = "Item15", ;
		TabIndex = 2, ;
		tip = T, ;
		Top = 63, ;
		ZOrderSet = 1, ;
		Label_item1.Caption = "Numar lot", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.lot", ;
		Text_item1.Format = "K!", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item16' AS item WITH ;
		Comment = "T", ;
		Left = 14, ;
		Name = "Item16", ;
		TabIndex = 3, ;
		tip = T, ;
		Top = 88, ;
		ZOrderSet = 1, ;
		Label_item1.Caption = "Data expirare", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.adata_expirare", ;
		Text_item1.Format = "K!", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item17' AS item WITH ;
		camp_lista = nrord, ;
		Comment = "T", ;
		fis_lista = Vnom_lucrari, ;
		id_fisier = id_lucrare, ;
		label_item = Lucrarea/Comanda, ;
		Left = 14, ;
		Name = "Item17", ;
		pcobj = orul, ;
		TabIndex = 13, ;
		TabStop = .F., ;
		tip = , ;
		Top = 333, ;
		ZOrderSet = 14, ;
		Label_item1.Caption = "Lucrare", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.nrord", ;
		Text_item1.ControlSource = "", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item2' AS item WITH ;
		Comment = "T", ;
		Left = 14, ;
		Name = "Item2", ;
		TabIndex = 5, ;
		tip = , ;
		Top = 140, ;
		ZOrderSet = 0, ;
		Label_item1.Caption = "Pret unitar de intrare NIR", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.pret", ;
		Text_item1.InputMask = (get_mask(12,gnPpret)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item3' AS item WITH ;
		Comment = "F", ;
		Left = 14, ;
		Name = "Item3", ;
		TabIndex = 6, ;
		tip = F, ;
		Top = 164, ;
		ZOrderSet = 7, ;
		Label_item1.Caption = "TVA (unitara)", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.tva", ;
		Text_item1.InputMask = (get_mask(12,gnPpret)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item4' AS item WITH ;
		Comment = "T", ;
		Left = 14, ;
		Name = "Item4", ;
		TabIndex = 7, ;
		tip = , ;
		Top = 188, ;
		ZOrderSet = 8, ;
		Label_item1.Caption = "Cantitate", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.cant", ;
		Text_item1.InputMask = (get_mask(12,gnPcant)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item5' AS item WITH ;
		Comment = "T", ;
		Left = 14, ;
		Name = "Item5", ;
		TabIndex = 8, ;
		tip = , ;
		Top = 212, ;
		ZOrderSet = 9, ;
		Label_item1.Caption = "Valoare ", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.valoare", ;
		Text_item1.InputMask = (get_mask(12,gnPc)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item6' AS item WITH ;
		Comment = "F", ;
		Left = 14, ;
		Name = "Item6", ;
		TabIndex = 9, ;
		tip = F, ;
		Top = 236, ;
		ZOrderSet = 10, ;
		Label_item1.Caption = "Valoare TVA", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.valoaretva", ;
		Text_item1.InputMask = (get_mask(12,gnPc)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item7' AS item WITH ;
		Comment = "A", ;
		Left = 14, ;
		Name = "Item7", ;
		TabIndex = 14, ;
		tip = A, ;
		Top = 355, ;
		ZOrderSet = 11, ;
		Label_item1.Caption = "Pret de vânzare cu TVA", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.PretvTva", ;
		Text_item1.InputMask = (get_mask(12,gnPPretV)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item8' AS item WITH ;
		Comment = "A", ;
		Left = 14, ;
		Name = "Item8", ;
		TabIndex = 15, ;
		tip = A, ;
		Top = 378, ;
		ZOrderSet = 12, ;
		Label_item1.Caption = "TVA vânzare", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.tvav", ;
		Text_item1.InputMask = (get_mask(12,gnPPretV)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item9' AS item WITH ;
		Comment = "X", ;
		Left = 14, ;
		Name = "Item9", ;
		TabIndex = 16, ;
		tip = A, ;
		Top = 401, ;
		ZOrderSet = 13, ;
		Label_item1.Caption = "Pret de vânzare fara TVA", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.pretv", ;
		Text_item1.InputMask = (get_mask(12,gnPPretV)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'lb_imputare' AS _label WITH ;
		BackStyle = 0, ;
		Caption = "Se imputa:", ;
		FontCharSet = 238, ;
		FontSize = 10, ;
		Height = 18, ;
		Left = 480, ;
		Name = "lb_imputare", ;
		TabIndex = 26, ;
		ToolTipText = "Se imputa", ;
		Top = 285, ;
		Width = 65
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_modparam' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Conversie", ;
		Comment = "F", ;
		FontCharSet = 238, ;
		FontName = "Arial", ;
		Height = 18, ;
		Left = 475, ;
		Name = "lb_modparam", ;
		TabIndex = 23, ;
		Top = 238, ;
		Width = 58, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_saft' AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Cod taxa", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Height = 18, ;
		Left = 475, ;
		Name = "lb_saft", ;
		TabIndex = 25, ;
		Top = 191, ;
		Visible = .F., ;
		Width = 54
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'lb_tva_achizitie' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "TVA achizitie", ;
		Comment = "F", ;
		FontCharSet = 238, ;
		FontName = "Arial", ;
		Height = 18, ;
		Left = 475, ;
		Name = "lb_tva_achizitie", ;
		TabIndex = 25, ;
		Top = 147, ;
		Visible = .T., ;
		Width = 79
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_tva_vanzare' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "TVA vânzare", ;
		Comment = "A", ;
		FontCharSet = 238, ;
		Height = 18, ;
		Left = 475, ;
		Name = "lb_tva_vanzare", ;
		TabIndex = 24, ;
		Top = 361, ;
		Visible = .T., ;
		Width = 75
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'Opt_imputare' AS optiongroup WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		BorderStyle = 0, ;
		ButtonCount = 2, ;
		Height = 43, ;
		Left = 474, ;
		Name = "Opt_imputare", ;
		TabIndex = 20, ;
		Top = 295, ;
		Value = 1, ;
		Width = 72, ;
		Option1.AutoSize = .T., ;
		Option1.BackStyle = 0, ;
		Option1.Caption = "procent", ;
		Option1.FontCharSet = 238, ;
		Option1.FontName = "Arial", ;
		Option1.FontSize = 10, ;
		Option1.Height = 18, ;
		Option1.Left = 5, ;
		Option1.Name = "Option1", ;
		Option1.ToolTipText = "procentul de durata ramasa din durata de folosinta", ;
		Option1.Top = 5, ;
		Option1.Value = 1, ;
		Option1.Width = 62, ;
		Option2.AutoSize = .T., ;
		Option2.BackStyle = 0, ;
		Option2.Caption = "integral", ;
		Option2.FontCharSet = 238, ;
		Option2.FontName = "Arial", ;
		Option2.FontSize = 10, ;
		Option2.Height = 18, ;
		Option2.Left = 5, ;
		Option2.Name = "Option2", ;
		Option2.ToolTipText = "integral", ;
		Option2.Top = 20, ;
		Option2.Width = 61
		*< END OBJECT: BaseClass="optiongroup" />
	
	PROCEDURE actualizeaza_explicatie_saft
		Local lcWhere, llAchizitie, llVisible
		If !m.gl406
			Return
		Endif
		
		llAchizitie =  (oset.model = 2) && 2 = NIR
		lcWhere = [.T.]
		IF m.llAchizitie
			lcWhere = [tva_achizitii=1]
			IF this.cbo_tva_achizitie.Visible
				lcWhere = lcWhere + [ and procent_taxa = jtva_achizitie.cota_tva]
			ENDIF 
		ELSE
			lcWhere = [tva_livrari=1]
			IF this.cbo_Tva_vanzare.Visible
				lcWhere = lcWhere + [ and procent_taxa = jtva_vanzare.cota_tva]
			ENDIF 
		ENDIF 
		
		* Pentru o factura de vanzare mut cbo_Saft sub cbo_tva_vanzare
		* Daca cbo_tva_vanzare este vizibil (ex: la vanzarea en-gros, cbo_tva_vanzare nu este vizibil)
		IF !m.llAchizitie AND This.cbo_tva_vanzare.Visible
			this.lb_saft.Top = this.cbo_tva_vanzare.Top + this.cbo_tva_vanzare.Height + 5
			this.cbo_saft.Top = this.lb_saft.Top + this.lb_saft.Height 
		ENDIF 
		
		With This
			llVisible = .cbo_saft.Visible
		
			* Cod taxa SAFT
			.cbo_saft.RowSourceType = 3 && sql
			.cbo_saft.RowSource = [Select descriere, taxcode, procent_taxa From saft_taxtable where ] + m.lcWhere + [ Order by taxcode Into Cursor crsTaxTableX]
			.cbo_saft.ControlSource = [Thisform.cobj.taxcode]
			.cbo_saft.BoundColumn = 2
			.cbo_saft.BoundTo = .T.
			.cbo_saft.ColumnCount = 3
			.cbo_saft.ColumnWidths = "500,50,50"
		
			.cbo_saft.Visible = m.llVisible && se pune Visible = .T. cand se face BoundTo = .T.
		Endwith
		This.UpdateExplicatieSAFT()
		 
	ENDPROC

	PROCEDURE aplicatva
		LPARAMETERS tcButonCaption && 24%
		
		Local lcCaption, lnCotaTva, lnPretCuTVA, lnPretFaraTVA, lnPretTVA
		lcCaption = m.tcButonCaption && 24%
		lnCotaTva = Val(Left(m.lcCaption, Len(m.lcCaption) - 1)) && 24
		If m.gnNeplatitoare_tva = 1
			lnPretFaraTVA = Thisform.item1.text_item1.Value
			lnPretTVA = 0
			lnPretCuTVA = Round(m.lnPretFaraTVA * (100 + m.lnCotaTva) / 100, m.gnPpret)
			* firma neplatitoare TVA. Presupun ca este pretul fara TVA si aplic TVA unitar la pretul fara TVA
			Thisform.item1.text_item1.Value = m.lnPretCuTVA
			Thisform.item2.text_item1.Value = m.lnPretCuTVA	
			Thisform.item3.text_item1.Value = m.lnPretTVA
		Else
			* firma platitoare TVA. Presupun ca este pretul cu TVA si scad TVA unitar din pretul cu TVA
			lnPretCuTVA = Thisform.item1.text_item1.Value
			lnPretTVA = Round(lnPretCuTVA * m.lnCotaTva / (100 + m.lnCotaTva), m.gnPpret)
			lnPretFaraTVA = lnPretCuTVA - lnPretTVA
			Thisform.item1.text_item1.Value = m.lnPretFaraTVA
			Thisform.item2.text_item1.Value = m.lnPretFaraTVA	
			Thisform.item3.text_item1.Value = m.lnPretTVA
		Endif
		
		* Schimb cota de TVA din cbo_tva_achizitie si cbo_tva_vanzare doar daca firma este platitoare TVA
		If m.gnNeplatitoare_tva = 0
			* Daca cota TVA achizitie <> cota TVA apasat, schimb TVA achizitie
			If Thisform.cbo_tva_achizitie.Visible
				Select jtva_achizitie
				lcColoanaAch = LEFT(coloana_jc,2) && RO[19NB]
				lnCotaTVAAch = cota_tva && 19
				lnIdJtvaAch = id_jtva_coloana
				IF m.lnCotaTVAAch <> m.lnCotaTVA
					LOCATE FOR cota_tva = m.lnCotaTVA AND LEFT(coloana_jc,2) = m.lcColoanaAch
					IF !FOUND()
						LOCATE FOR id_jtva_coloana = m.lnIdJtvaAch
					ENDIF 
				ENDIF 
				lnIdJtvaAch = id_jtva_coloana
				thisform.cbo_tva_achizitie.Value = m.lnIdJtvaAch
				Thisform.do_alege_tvaach()
			ENDIF
		
			* Daca cota TVA vz <> cota TVA apasat, schimb TVA vz
			If Thisform.cbo_tva_vanzare.Visible
				Select jtva_vanzare
				lcColoanaVz = LEFT(coloana_jc,2) && RO[19NB]
				lnCotaTVAVz = cota_tva && 19	
				lnIdJtvaVz = id_jtva_coloana
				IF m.lnCotaTVAVz <> m.lnCotaTVA
					LOCATE FOR cota_tva = m.lnCotaTVA AND LEFT(coloana_jv,2) = m.lcColoanaVz
					IF !FOUND()
						LOCATE FOR id_jtva_coloana = m.lnIdJtvaVz
					ENDIF 
				ENDIF 
				lnIdJtvaVz = id_jtva_coloana
				Thisform.cbo_tva_vanzare.Value = m.lnIdJtvaVz
				Thisform.do_alege_tvavanz()
			ENDIF  
		ENDIF && m.gnNeplatitoare_tva
		
		Thisform.item1.text_item1.Refresh()
		Thisform.item2.text_item1.Refresh()
		Thisform.item3.text_item1.Refresh()
		Thisform.item1.text_item1.SetFocus()
		
	ENDPROC

	PROCEDURE calculeaza_tva_ach
		Thisform.cobj.tva = Round(Thisform.cobj.Pret * (Thisform.cobj.proc_tva - 1),gnPpret)
		Thisform.item3.Refresh()
	ENDPROC

	PROCEDURE calculeaza_valori_ach
		Lparameters tnCantitate
		Local lnCantitate, lnPret, lnTva, lnProcTva, lnValoareACTva, lnValoareATva, lnValoareACTva
		lnCantitate = tnCantitate
		If !Thisform.blochezPretV And poact.id_set <> 104 && (la imputare, sa ma lase sa pun cu mana pretv)
			Thisform.cobj.TVAV = Round(Thisform.PRETVTVA * (Thisform.cobj.proc_tvav-1)/Iif(Thisform.cobj.proc_tvav <> 0, Thisform.cobj.proc_tvav,1), gnPPretV)
			Thisform.cobj.PRETV = Thisform.PRETVTVA - Thisform.cobj.TVAV
		Endif
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent=Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		Thisform.item8.Refresh
		Thisform.item9.Refresh
		Thisform.clb_item_adaos.Refresh
		*!* v 2.0.24
		lnPret = Thisform.cobj.Pret
		lnTva = Thisform.cobj.TVA
		lnProcTva = Iif(Thisform.cobj.PROC_TVA <> 0, Thisform.cobj.PROC_TVA, TVA2PROCTVA(lnTva, lnPret))
		*!* in stoc nu exista coloana proc_tva !!! o calculez si o pun in rulaj
		Thisform.cobj.PROC_TVA = lnProcTva
		If !plNIRBONPretCuTVA
			lnValoareAFTva = Round(lnCantitate*lnPret, gnPc)
			lnValoareATva = Round(lnValoareAFTva * (lnProcTva-1), gnPc)
			lnValoareACTva = lnValoareAFTva + lnValoareATva
		Else
			lnValoareACTva = Round(lnCantitate*(lnPret+lnTva), gnPc)
			lnValoareATva = Round(lnValoareACTva * (lnProcTva - 1) / lnProcTva, gnPc)
			lnValoareAFTva = lnValoareACTva - lnValoareATva
		Endif
		Thisform.valoare = lnValoareAFTva
		Thisform.VALOAREtva = lnValoareATva
		*!* v 2.0.24 ^
		Thisform.item5.Refresh
		Thisform.item6.Refresh
	ENDPROC

	PROCEDURE do_alege_reteta
		LOCAL lcselect,lcFiltru,lcSchema,lcOrder,lccoloane,lcTitlu,lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal, lnPornire, llDesktop
		lcselect = [select id_reteta, reteta from vnom_retetar]
		lcSchema = []
		lcOrder = [reteta]
		lccoloane = [reteta]
		lcTitlu = [Alegeti fisa tehnologica]
		lcTitluColoane = [Fisa tehnologica]
		lcFiltru = []
		lcFiltruOriginal = [principala=0 and id_articol=]+ALLTRIM(STR(thisform.cobj.id_articol))
		lcNumeProc = []
		llToateIreg = .F.
		lnPornire = 1
		llDesktop = .F.
		locauta = cauta_alfa(lcselect,lcFiltru,lcSchema,lcOrder,lccoloane,lcTitlu,lcTitluColoane, lcNumeProc, llToateIreg, lcFiltruOriginal,,lnPornire,,,llDesktop)		&& 11.07.2007
		
		IF buton = 2
			RETURN
		ENDIF
		
		thisform.cobj.id_reteta = locauta.id_reteta 
		thisform.cobj.reteta = locauta.reteta 
		
		
		
		
		
		
	ENDPROC

	PROCEDURE do_alege_tvaach
		Thisform.COBJ.PROC_TVA = (jtva_achizitie.cota_tva + 100 ) / 100
		Thisform.COBJ.id_jtva_coloana = jtva_achizitie.id_jtva_coloana
		
		This.actualizeaza_explicatie_saft()
		
		*!*	modificare	ROAFACTURARE v 2.2.20
		*!*	Thisform.item1.teXT_ITEM1.Valid
		Thisform.calculeaza_tva_ach()
		Thisform.calculeaza_valori_ach(Thisform.item4.text_item1.Value)
		*!*	modificare	ROAFACTURARE v 2.2.20	^
		
		
	ENDPROC

	PROCEDURE do_alege_tvavanz
		If !('F' $ Thisform.bVizualizare)
			Thisform.COBJ.id_jtva_coloana = jtva_vanzare.id_jtva_coloana
		Endif
		If !Thisform.blochezPretV
			Thisform.COBJ.PROC_TVAv = (jtva_vanzare.cota_tva + 100)/100
			Thisform.PROC_TVAv = (jtva_vanzare.cota_tva + 100)/100
			Thisform.item7.teXT_ITEM1.InteractiveChange
		ENDIF
		
		This.actualizeaza_explicatie_saft()
	ENDPROC

	PROCEDURE do_executa
		*!*	this.cobj.pretv = ROUND(this.cobj.pret * (1 + this.cobj.procent/100), gnPpret)
		*!*	this.cobj.TVAV = ROUND(this.cobj.PRETV*(this.cobj.proC_TVAV-1), gnPpret)
		If !plNIRBONPretCuTVA
			This.cobj.pretv = Round(This.cobj.Pret * (1 + This.cobj.procent/100), gnPPretV)
			This.cobj.TVAV = Round(This.cobj.pretv*(This.cobj.proC_TVAV-1), gnPPretV)
			This.PRETVTVA = This.cobj.pretv + This.cobj.TVAV
		Else
			This.cobj.pretv = Round(This.cobj.Pret * (1 + This.cobj.procent/100), gnPPretV)
			thisform.pretvtva = Round((This.cobj.Pret + This.cobj.Tva) * (1 + This.cobj.procent/100), gnPPretV)
			This.cobj.TVAV = thisform.pretvtva - This.cobj.pretv
		EndIf 	
		This.item7.Refresh
		This.item8.Refresh
		This.item9.Refresh
		
	ENDPROC

	PROCEDURE do_modiparam
		Private pnTransformat, pnPretTr, ofrmconversie
		Store 0 To pnTransformat, pnPretTr
		
		ofrmconversie=Createobject('frm_conversie',Thisform.cobj.Pret,Thisform.cobj.um,Thisform.cobj.cant)
		ofrmconversie.Show(1)
		Release ofrmconversie
		
		If gnButon=1
		*!*	modificare	v 2.0.150
		*!*		Thisform.pretu_factura = pnPretTr
		*!*		Thisform.cobj.Pret = pnPretTr
		*!*		Thisform.item1.Refresh()
		*!*		Thisform.item1.SetFocus()
		
		*!*		Thisform.item2.Refresh()
		*!*		Thisform.item2.SetFocus()
		
		*!*		Thisform.cobj.cant = pnTransformat
		*!*		Thisform.item4.Refresh()
		*!*		Thisform.item4.SetFocus()
			Thisform.item1.text_item1.Value = pnPretTr
			Thisform.item2.text_item1.Value = pnPretTr
			Thisform.item4.text_item1.Value = pnTransformat
			Thisform.item1.Refresh()
			Thisform.item1.SetFocus()	
			Thisform.item2.Refresh()
			Thisform.item2.SetFocus()
			Thisform.item4.Refresh()	
			Thisform.item4.SetFocus()	
		*!*	modificare	v 2.0.150	^
		Endif
		
	ENDPROC

	PROCEDURE inainte_de_do_termin
		Local llReturn
		Store .T. To llReturn
		 
		If oset.model = 2
			Thisform.cobj.Cont = Thisform.item14.text_item1.Value
			lcCont = Thisform.cobj.Cont
			If Empty(Nvl(lcCont,[]))
				amessagebox("Nu ati completat contul!",48,"Atentie")
				Thisform.item14.SetFocus()
				llReturn = .F.
			Else
				lcSql = [begin ] + gcS + [.verifica_plcont_sintetic(?gnAn,'] + Alltrim(lcCont) + ['); end;]
				lnSucces = goExecutor.oExecute(lcSql)
				If lnSucces < 0
					amessagebox(goExecutor.oPrelucrareEroare(),16,"Eroare")
					Thisform.item14.SetFocus()
					llReturn = .F.
				Endif
			Endif
		ENDIF
		*!* 27.05.2009 - cantitatea introdusa plus cantitatea iesita nu trebuie sa depaseasca cantitatea din stoc.
		*!* marius.felecanu
		IF thisform.ncant_stoc <> 0
		   IF thisform.ncant_iesita + thisform.item4.text_item1.Value > thisform.ncant_stoc 
			  AMESSAGEBOX("Cantitatea maxima existenta este: " + ALLTRIM(STR(thisform.ncant_stoc - thisform.ncant_iesita,18,4)),0+48,_screen.Caption)
			  llReturn = .F.
			  thisform.item4.SetFocus() 
			ENDIF 
		ENDIF 	  
		*!* 27.05.2009 ^
		
		*!* 09.06.2008
		*!* id_set = 231 nir mf la pv cu modificarea listei de preturi
		If Type('poPreturi') = 'O'
			poPreturi.pretv = this.cobj.pretv
			poPreturi.tvav = this.cobj.tvav
			poPreturi.pretvtva = this.PretvTva
		EndIf 
		*!* 09.06.2008 ^
		*!*	modificare ROAGEST	v 2.0.53
		If InList(oset.id_set,238,239,259,260,267)
			Thisform.COBJ.id_jtva_coloana = jtva_vanzare.id_jtva_coloana
		EndIf
		*!*	modificare ROAGEST	v 2.0.53	^
		*!*	modificare	ROAGEST v 2.2.29
		If llReturn And !Isnull(Thisform.omemopref)
			Thisform.omemopref.id_jtva_ach = jtva_achizitie.id_jtva_coloana
			Thisform.omemopref.proc_tva = (jtva_achizitie.cota_tva + 100)/100
			Thisform.omemopref.id_jtva_vanz = jtva_vanzare.id_jtva_coloana
			Thisform.omemopref.proc_tvav = (jtva_vanzare.cota_tva + 100)/100
		Endif
		*!*	modificare	ROAGEST v 2.2.29	^
		Return llReturn
	ENDPROC

	PROCEDURE Init
		*!*	modificare	ROAGEST v 2.2.29
		LPARAMETERS toDatePref
		DODEFAULT()
		Thisform.omemopref = IIF(TYPE("toDatePref")="O",toDatePref,NULL)
		*!*	modificare	ROAGEST v 2.2.29	^
	ENDPROC

	PROCEDURE KeyPress
		Lparameters nKeyCode, nShiftAltCtrl
		Do Case
			Case nKeyCode = 19 And nShiftAltCtrl = 4 And Thisform.item12.Visible &&  ALT + R
				Nodefault
				Thisform.do_alege_reteta()
			Case nKeyCode=13 And nShiftAltCtrl=2
				Nodefault
				If Pemstatus(This,"do_modiparam",5)
					This.do_modiparam()
				Endif
			Otherwise
				DoDefault(nKeyCode, nShiftAltCtrl)
		Endcase
	ENDPROC

	PROCEDURE Load
		If !Used('saft_taxtable')
			update_saft_taxtable()
		Endif
		
	ENDPROC

	PROCEDURE Show
		*!* 01.07.2010
		*!* MARIUS.MUTU
		*!* folosesc GetIdJtvaStandard - este relativa la luna contabila
		
		*!* 09.03.2014
		*!* marius.mutu
		*!* Fac vizibile maxim 4 butoane cmdCotaTVA - pentru aplicarea cotei tva la pretul unitar de achizitie fara TVA
		*!*	In cazul firmelor neplatitoare de TVA, pretul unitar de achizite fara TVA include si TVA unitar
		
		*!* 12.06.2015
		*!* marius.mutu
		*!* setare explicatie tva 24% sau 9% pentru fct. achizitie cu politica de preturi, dupa cota de tva din politica de preturi
		
		*!* 03.01.2016
		*!* marius.mutu
		*!* jtva_achizitie - setare TVA achizitie independent de xsets.id_jtax
		
		*!* 20.11.2017
		*!* marius.mutu
		*!* jtva_achizitie - setare TVA achizitie preluand id_jtva de la articolul anterior
		
		Lparameters nStyle
		lnHeight = 0
		
		* DARE IN FOLOSINTA OBIECTE DE INVENTAR. POT SA COMPLETEZ SERIA (NR INVENTAR) PENTRU CA INTRA IN RUL_OBINV CA INTRARE NOUA
		* schimb thisform.cobj.serie in thisform.cobj_serie_obinv, ca sa o pot modifica
		IF INLIST(oset.id_set , 55, 273) && dare in folosinta
			thisform.item13.text_item1.Comment = 'thisform.cobj.serie_obinv'
			* In caz ca este deja completata seria, o preiau pe serie_obinv
			thisform.cobj.serie_obinv = thisform.cobj.serie
			thisform.item13.text_item1.ReadOnly = .F.	
		ENDIF 
		
		
		For Each loControl In This.Controls
			With loControl
				If !Empty(loControl.Comment)
					If .Comment $ This.bVizualizare
						.Visible = .T.
						If 'ITEM' $ Upper(.Name)
							For Each loCtrSecund In loControl.Controls
								If 'TEXT' $ Upper(loCtrSecund.Name)
									lcControlSource = Alltrim(loCtrSecund.Comment)
									loCtrSecund.ControlSource = lcControlSource
								Endif
							Endfor
							*!*						lcControlSource = ALLTRIM(.text_item1.comment)
							*!*						.text_item1.controlsource = lcControlSource
							.pcobj = 'orul'
						Endif
						lnTop = .Top
						If lnTop > lnHeight
							lnHeight = lnTop
						Endif
					Else
						.Visible = .F.
					Endif
				Endif
			Endwith
		Endfor
		SET STEP ON 
		IF m.gnNeplatitoare_tva <> 1 AND this.cbo_tva_achizitie.Visible
			*!*	modificare 21.02.2007
			*** Daca sunt la al doilea articol, preiau id_jtva_coloana de la articolul anterior
			llFound = .F.
			If !Empty(Thisform.cobj.id_jtva_coloana)
				Select jtva_achizitie
				Locate For id_jtva_coloana = Thisform.cobj.id_jtva_coloana
				llFound = Found()
			Endif
		
			If !m.llFound
				Select jtva_achizitie
				Do Case
					*!*	modificare	ROAGEST v 2.0.53
					Case Inlist(oset.id_set,238,239,259,260,267)
						&& Mf pv - Aviz retur marfa (valoric);Mf pv - Factura retur marfa (valorica);Mf pv - Factura retur marfa (valorica);Aviz retur marfa (valoric)
						*!* 01.07.2010
						Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE')	&&	modificare v 2.2.0 : conditia de dupa or && 103
						*!* 01.07.2010 ^
						*!*	modificare	ROAGEST v 2.0.53	^
					Case Type('poAct.id_pol') = 'N' And Type('poAct.proc_tvav') = 'N' And !Empty(Nvl(poAct.id_pol,0)) And !Empty(Nvl(poAct.PROC_TVAv,0))
						Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_VANZARE', poAct.PROC_TVAv) Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_VANZARE', poAct.PROC_TVAv) Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_MATERII', poAct.PROC_TVAv)
		
					Case Alltrim(This.cobj.Cont) = '371' And Inlist(oset.id_jtax, 137, 139, 141, 162, 186,216)		&&	taxare inversa 19%, 162 = 24%, 186 = 20%, 216=21%
						Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_TI_VANZARE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_TI_VANZARE') && 139
		
					Case Alltrim(This.cobj.Cont) = '371' And Inlist(oset.id_jtax, 101, 103,105, 156, 176,208)		&&	marfa 19 %, 156 = 24%, 176 = 20%, 208=21%
						Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_VANZARE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_VANZARE') && 103
						If !Found()
							Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_MATERII') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_MATERII') && 105
						Endif
		
					Case Alltrim(This.cobj.Cont) = '371'
						Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_VANZARE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_VANZARE')
						If !Found()
							Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_MATERII') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_MATERII') && 105
						Endif
		
					Case Inlist(Left(Alltrim(This.cobj.Cont),2), '30', '31', '32')
						Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE')
						If !Found()
							Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_VANZARE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_VANZARE') && 103
						Endif
		
					Otherwise
						Locate For id_jtva_coloana = oset.id_jtax Or id_jtva_ex = oset.id_jtax	&&	modificare v 2.2.0 : conditia de dupa or
				Endcase
			ENDIF && !m.llFound
		
			If Found()
				*!*			This.cbo_tva_achizitie.Value = Alltrim(denumire)	v 2.2.29
				Thisform.cobj.id_jtva_coloana = id_jtva_coloana
				This.cobj.proc_tva = (COTA_TVA + 100)/100
			Endif
			*!*		SELECT cote_tva
			*!*		GO TOP
			*!*	modificare 21.02.2007 ^
		Endif
		SET STEP ON 
		If 'F' $ This.bVizualizare And Empty(This.cobj.proc_tva) AND this.cbo_tva_achizitie.Visible
			*!*	modificare 21.02.2007
			Select jtva_achizitie
			Do Case
		
				Case Type('poAct.id_pol') = 'N' And Type('poAct.proc_tvav') = 'N' And !Empty(Nvl(poAct.id_pol,0)) And !Empty(Nvl(poAct.PROC_TVAv,0))
					Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_VANZARE', poAct.PROC_TVAv) Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_VANZARE', poAct.PROC_TVAv) Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_MATERII', poAct.PROC_TVAv)
		
				Case Alltrim(This.cobj.Cont) = '371' And Inlist(oset.id_jtax, 137, 139, 141, 162, 186,216)		&&	taxare inversa 19%, 162 = 24%, 186 = 20%
					Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_TI_VANZARE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_TI_VANZARE') && 139
		
				Case Alltrim(This.cobj.Cont) = '371' And Inlist(oset.id_jtax, 101,103,105, 156, 176,208)		&&	marfa 19 %, 156 = 24%, 176 = 20%
					Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_VANZARE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_VANZARE') && 103
		
				Case Alltrim(This.cobj.Cont) = '371'
					Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE_VANZARE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE_VANZARE')
		
				Case Inlist(Left(Alltrim(This.cobj.Cont),2), '30', '31', '32')
					Locate For id_jtva_coloana = GetIdJtvaStandard('ACHIZITIE') Or id_jtva_ex = GetIdJtvaStandard('ACHIZITIE')
		
				Otherwise
					Locate For id_jtva_coloana = oset.id_jtax Or id_jtva_ex = oset.id_jtax	&&	modificare v 2.2.0 : conditia de dupa or
			Endcase
			If Found()
				*!*			This.cbo_tva_achizitie.Value = Alltrim(denumire)	v 2.2.29
				Thisform.cobj.id_jtva_coloana = id_jtva_coloana
				This.cobj.proc_tva = (COTA_TVA + 100)/100
			Endif
			*!*		SELECT cote_tva
			*!*		* GO top
			*!*		lnProc_tva = proc_tva
			*!*		lnproc = procent
			*!*		THIS.cotaTVA_achizitie.VALUE = ALLTRIM(STR(lnproc))
			*!*		THIS.cobj.proc_tva = lnProc_tva
			*!*	modificare 21.02.2007 ^
		Endif
		SET STEP ON 
		If 'A' $ This.bVizualizare
			If This.blochezPretV
				This.item7.Enabled = .F.
				This.item8.Enabled = .F.
				This.item9.Enabled = .F.
				This.Clb_ITEM_adaos.Visible = .F.
				*!*	modificare 21.02.2007
				lcFiltru = [cota_tva = ] + Alltrim(Str(Thisform.cobj.PROC_TVAv * 100 - 100))
				Select jtva_vanzare
				Set Filter To &lcFiltru
				Go Top
				*!*			This.cbo_tva_VANZARE.Value = Alltrim(denumire)	v 2.2.29
				If !('F' $ This.bVizualizare)
					This.cobj.id_jtva_coloana = id_jtva_coloana
				Endif
				*!*			THIS.CotaTVA_vanzare.ENABLED = .F.
				*!*			THIS.CotaTVA_vanzare.VALUE = ALLTRIM(STR(THIS.proc_tvav *100 - 100))
				*!*	modificare 21.02.2007	^
			Else
				*!*	modificare 21.02.2007
				Select jtva_vanzare
				Go Top
				*!* 01.07.2010
				If Type('poAct.id_pol') = 'N' And Type('poAct.proc_tvav') = 'N' And !Empty(Nvl(poAct.id_pol,0)) And !Empty(Nvl(poAct.PROC_TVAv,0))
					Locate For id_jtva_coloana = GetIdJtvaStandard('VANZARE', poAct.PROC_TVAv) Or id_jtva_ex = GetIdJtvaStandard('VANZARE', poAct.PROC_TVAv)
				Else
					*!*			Locate For id_jtva_coloana = Iif(oset.tipjurnal=[JV],oset.id_jtax,1)
					Locate For id_jtva_coloana = Iif(oset.tipjurnal=[JV],oset.id_jtax,GetIdJtvaStandard('VANZARE')) Or id_jtva_ex = Iif(oset.tipjurnal=[JV],oset.id_jtax,GetIdJtvaStandard('VANZARE'))	&&	modificare v 2.2.0 : conditia de dupa or
				Endif
				*!* 01.07.2010 ^
				If Found()
					*!*				This.cbo_tva_VANZARE.Value = id_jtva_coloana	v 2.2.29
					This.cobj.PROC_TVAv = (COTA_TVA + 100)/100
					If !('F' $ This.bVizualizare)
						This.cobj.id_jtva_coloana = id_jtva_coloana
					Endif
				Endif
				*!*			SELECT cote_tva
				*!*			* GO top
				*!*			lnProc_tva = proc_tva
				*!*			lnproc = procent
				*!*			THIS.CotaTVA_vanzare.VALUE = ALLTRIM(STR(lnproc))
				*!*			THIS.cobj.proc_tvav = lnProc_tva
				*!*	modificare 21.02.2007 ^
			Endif
		
			This.cobj.procent = Thisform.proc_adaos
		Endif
		
		*!*	modificare	ROAGEST v 2.2.29
		Local lnIdJtvaAles
		If Inlist(oxset.id_set, 232, 235, 244, 262)	&&	protocol fara TVA, sponsorizare
			Select jtva_vanzare
			lnIdJtvaAles = id_jtva_coloana
			Set Filter To COTA_TVA = 0
			Locate For id_jtva_coloana = lnIdJtvaAles
			If !Found()
				Go Top
			Endif
		Endif
		
		* se tine cont de cota de la ultimul articol ales, dar nu si pentru achizitiile cu lista preturi de vanzare, la care am luat cota de tva din lista de preturi
		If !Isnull(Thisform.omemopref) And !(Type('poAct.id_pol') = 'N' And Type('poAct.proc_tvav') = 'N' And !Empty(Nvl(poAct.id_pol,0)) And !Empty(Nvl(poAct.PROC_TVAv,0)))
			Select jtva_achizitie
			lnIdJtvaAles = id_jtva_coloana
			Locate For id_jtva_coloana = Evl(Thisform.omemopref.id_jtva_ach,lnIdJtvaAles)
			If !Found()
				Locate For id_jtva_coloana = lnIdJtvaAles
			Endif
			If Thisform.cbo_tva_achizitie.Visible
				Thisform.do_alege_tvaach()
			Endif
		
			Select jtva_vanzare
			lnIdJtvaAles = id_jtva_coloana
			Locate For id_jtva_coloana = Evl(Thisform.omemopref.id_jtva_vanz,lnIdJtvaAles)
			If !Found()
				Locate For id_jtva_coloana = lnIdJtvaAles
			Endif
			If Thisform.cbo_tva_vanzare.Visible
				Thisform.do_alege_tvavanz()
			Endif
		Endif
		Release lnIdJtvaAles
		*!*	modificare	ROAGEST v 2.2.29	^
		
		* 31.08.2020
		* Fac vizibile maxim 4 butoane cmdCotaTVA - pentru aplicarea/scaderea cotei tva la pretul unitar de achizitie fara/cu TVA
		* In cazul firmelor neplatitoare de TVA, se scrie pretul fara TVA, iar cand se apasa butonul se va include si TVA unitar
		* In cazul firmelor platitoare de TVA, se scrie pretul cu TVA de pe bonul fiscal, iar cand se apasa butonul se defalca in pret fara TVA si TVA unitar
		IF this.item1.Visible && pret unitar pe factura
			Select Distinct COTA_TVA From jtva_achizitie Where COTA_TVA <> 0 Order By COTA_TVA Desc Into Array laCoteTVA
			lnCoteTVA = _Tally
			For lnCotaIdx = 1 To Min(m.lnCoteTVA, 5) && 5 cote maxim
				lcControl = 'thisform.cmdTVA' + Alltrim(Str(m.lnCotaIdx))
				lnCotaTVA = laCoteTVA[m.lnCotaIdx]
				lcCaption = Alltrim(Str(m.lnCotaTVA)) + '%'
				&lcControl..Caption = m.lcCaption
				&lcControl..ToolTipText = IIF(m.gnNeplatitoare_tva = 1, 'Aplica TVA la pretul fara TVA', 'Scade TVA din pretul cu TVA')
				&lcControl..Visible = .T. && este deja vizibil
			ENDFOR
		ENDIF 
		
		*!* firmele neplatitoare de TVA sunt intitializate cu cota TVA 0%
		If m.gnNeplatitoare_tva = 1
			*!*	modificare 21.02.2007
			Select jtva_achizitie
			Locate For id_jtva_coloana = 113
			If Found()
				*!*			This.cbo_tva_achizitie.Value = Alltrim(denumire)	v 2.2.29
				Thisform.cobj.id_jtva_coloana = id_jtva_coloana
				This.cobj.proc_tva = (COTA_TVA + 100)/100
			Endif
			Select jtva_vanzare
			Locate For id_jtva_coloana = 11
			If Found()
				*!*			This.cbo_tva_VANZARE.Value = Alltrim(denumire)		v 2.2.29
				Thisform.cobj.PROC_TVAv = (jtva_vanzare.COTA_TVA + 100)/100
				Thisform.PROC_TVAv = (jtva_vanzare.COTA_TVA + 100)/100
				If !('F' $ This.bVizualizare)
					This.cobj.id_jtva_coloana = id_jtva_coloana
				Endif
			Endif
		ENDIF 
			*!*	modificare 21.02.2007	^
			
		* Factura vanzare si nu este vizibil cbo_tva_vanzare
		llAchizitie =  (oset.model = 2) && 2 = NIR
		IF oset.factura AND !m.llAchizitie AND !this.cbo_tva_vanzare.Visible AND TYPE('poAct.id_jtva_coloana') = 'N'
			SELECT jtva_vanzare
			LOCATE FOR id_jtva_coloana = poAct.id_jtva_coloana
			IF FOUND()
				Thisform.cobj.id_jtva_coloana = id_jtva_coloana
				This.cobj.proc_tva = (COTA_TVA + 100)/100
			ENDIF 	
		ENDIF 
		
		
		If 'B' $ This.bVizualizare
			This.item4.SetFocus
		ENDIF
		
		* 55,273 Dare in folosinta, ma pozitionez pe serie
		IF INLIST(oset.id_set, 55,273)
			this.item13.SetFocus
		ENDIF 
		
		*!* 29.09.2006
		*!* MARIUS.MUTU
		*!* RETETA VIZIBILA DOAR IN ROAPRODUCTIE.pv_productie (FOARTE POSIBIL SI IN ROAGEST - PV PRODUCTIE)
		If Inlist(poAct.id_set,26001)
			This.ITEM12.Visible = .T.
			This.IMAGE1.Visible = .T.
		Else
			This.ITEM12.Visible = .F.
			This.IMAGE1.Visible = .F.
		Endif
		
		&& opt_imputare
		If Inlist(poAct.id_set,104) And gnImputare = 1
			This.lb_imputare.Visible = .T.
			This.opt_imputare.Visible= .T.
		Else
			This.lb_imputare.Visible = .F.
			This.opt_imputare.Visible = .F.
		Endif
		
		If poAct.id_set = 105 && NIR de marfa la pret de vanzare
			This.item7.text_item1.ReadOnly = .T.
			This.item9.text_item1.ReadOnly = .T.
			This.Clb_ITEM_adaos.text_simplu1.ReadOnly = .T.
		Endif
		
		*!*	modificare 22.06
		This.but_modiparam1.Visible=This.item4.Visible
		This.lb_modparam.Visible=This.item4.Visible
		*!*	^
		
		This.Height = lnHeight + 90 && ultimul item + 90 (pentru lbs_saft si cbo_saft)
		This.lb_titlu_alb_b121.Caption = This.cTitlu
		
		*!*	modificare	20.08.2007
		If oset.model = 2
			This.item13.text_item1.ReadOnly = .F.
			This.item14.text_item1.ReadOnly = .F.
			this.item14.text_item2.ReadOnly = .F.
		
			*!*	modificare	18.01.2008
			This.item15.text_item1.ReadOnly = .F.
			This.item16.text_item1.ReadOnly = .F.
			*!*	modificare	18.01.2008 ^
		Endif
		*!*	modificare	20.08.2007	^
		
		*!*	modificare	v 2.2.29 : le-am initializat aici pentru ca s-a intamplat uneori sa imi apara formularul,
		*!*		dar sa nu am selectata nicio valoare in combo, iar daca inchideam fereastra si o lansam din nou,
		*!*		de abia atunci imi aparea valoarea selectata
		With Thisform.cbo_tva_achizitie
			If .Visible
				.ColumnCount = 3
				.ColumnLines = .F.
				.ColumnWidths = [200,10,0]
				.RowSource = [jtva_achizitie.denumire,cota_tva,id_jtva_coloana]
				.RowSourceType = 6
				.BoundColumn = 3
				.BoundTo = .T.
				.Value = jtva_achizitie.id_jtva_coloana		&&	Substr(jtva_achizitie.denumire,1,200)
			Endif
		Endwith
		With Thisform.cbo_tva_vanzare
			If .Visible
				.ColumnCount = 3
				.ColumnLines = .F.
				.ColumnWidths = [200,10,0]
				.RowSource = [jtva_vanzare.denumire,cota_tva,id_jtva_coloana]
				.RowSourceType = 6
				.BoundColumn = 3
				.BoundTo = .T.
				.Value = jtva_vanzare.id_jtva_coloana		&&	Substr(jtva_achizitie.denumire,1,200)
			Endif
		ENDWITH
		
		IF m.gl406 AND oset.factura AND (this.cbo_tva_achizitie.Visible OR this.cbo_tva_vanzare.Visible)
			* FACTURA + MODEL = 2 (NIR)
			* Factura vanzare en-gros nu are vizibila cbo_tva_vanzare
			This.cbo_saft.Visible = .T.
			this.lb_saft.Visible = .T.
			This.actualizeaza_explicatie_saft()
		ELSE
			IF m.gl406 AND oset.factura
				* Daca este factura , dar nu este vizibil cbo_saft (ex: vanzare en-gros)
				This.UpdateExplicatieSAFT()
			ENDIF 
		ENDIF 	
		
		*!*	modificare	v 2.2.29	^
		If oset.id_set = 85 && MATERIALE RECUPERATE
			Thisform.cobj.PROC_TVA = 1 && ORUL.PROC_TVA = 1  nu are procent TVA 
		ENDIF 
		
		
		DoDefault()
		
	ENDPROC

	PROCEDURE updateexplicatiesaft
		LOCAL llAchizitie, laNesosit[1]
		Local llN100, llN50, llNeexigibil
		* tlAchizitie: .T. = factura achizitie
		
		Local ldDataAct, lnIdJtva, lnIdPart, llFurnizorRTVAI, lcProcentTaxa, lnTaxCode
		
		If !m.gl406
			Return
		ENDIF
		
		llAchizitie =  (oset.model = 2) && 2 = NIR
		
		ldDataAct = poAct.dataact
		If m.llAchizitie
			lnIdJtva = jtva_achizitie.id_jtva_coloana
		Else
			lnIdJtva = jtva_vanzare.id_jtva_coloana
		ENDIF
		
		llFurnizorRTVAI = .F.
		IF TYPE('pcobj.oPartenerRTVAI') = 'O'
			llFurnizorRTVAI = IIF(m.llAchizitie, IIF(PEMSTATUS(pcobj.oPartenerRTVAI, 'leinRtvai',5), pcobj.oPartenerRTVAI.leinRtvai, .F.), .F.) && poAct
		ENDIF 
		
		* llN50/llN100 = .T. doar pentru linia cu Explicatie TVA = "Limitare deducere TVA"
		llN50 = .F. && (m.lnIdSet = 10609) && limitare deducere 50%
		llN100 = .F. && (m.lnIdSet = 10647) && limitare deducere 100%
		SELECT COUNT(*) as nr FROM xnote WHERE id_set = oset.id_set AND (LEFT(xscd,3) = '418' OR LEFT(xscc,3) = '408') INTO ARRAY laNesosit
		llNeexigibil = (laNesosit[1] > 0) && factura neintocmita/nesosita
		
		lnTaxCode = GetTaxCode(m.gnAn, m.gnLuna, m.ldDataAct, m.lnIdJtva, m.llFurnizorRTVAI, m.llN50, m.llN100, m.llNeexigibil)
		
		Thisform.cobj.taxcode = m.lnTaxCode
		
		This.UpdateLabelSaft(m.lnTaxCode)
		This.cbo_saft.Refresh()
		
		
		
		   
	ENDPROC

	PROCEDURE updatelabelsaft
		LPARAMETERS lnTaxCode
		
		Local lcProcentTaxa
		lcProcentTaxa = ''
		
		IF SEEK(m.lnTaxCode, 'saft_taxtable', 'taxcode') 
			lcProcentTaxa = Alltrim(Transform(saft_taxtable.procent_taxa)) + '%'
		ENDIF 
		
		This.lb_saft.Caption = 'Taxa SAFT' + Iif(!Empty(NVL(m.lnTaxCode,0)), ' (' + Alltrim(Transform(m.lnTaxCode)) + ' ' + m.lcProcentTaxa + ')', '')
		* Schimb in culoarea rosie pentru a atentiona utilizatorul ca valoarea a fost schimbata
		This.lb_saft.ForeColor = Rgb(255, 0, 0)
		This.lb_saft.Refresh()
		 
	ENDPROC

	PROCEDURE updatepaymentsaft
		If !m.gl406
			Return
		Endif
		
		lnIdFdoc = Nvl(poAct.id_fdoc,0)
		
		If !Empty(m.lnIdFdoc)
			This.cPaymentCode = GetPaymentCode(m.lnIdFdoc)
		Else
			This.cPaymentCode = ''
		Endif
		This.cbo_plata_saft.Refresh()
		
	ENDPROC

	PROCEDURE cbo_saft.LostFocus
		This.ForeColor = Rgb(0, 0, 0)
		
	ENDPROC

	PROCEDURE cbo_saft.Valid
		Thisform.UpdateLabelSaft(Thisform.cobj.taxcode)
		
	ENDPROC

	PROCEDURE cbo_tva_achizitie.Valid
		Thisform.do_alege_tvaach()
	ENDPROC

	PROCEDURE cbo_tva_vanzare.Valid
		Thisform.do_alege_tvavanz()
	ENDPROC

	PROCEDURE Clb_ITEM_adaos.TEXT_SIMPLU1.InteractiveChange
		lcAtribuieValoare = This.ControlSource + [ = ] + Alltrim(Str(This.Value,12,2))
		&lcAtribuieValoare
		Thisform.do_executa()
		
	ENDPROC

	PROCEDURE Clb_ITEM_adaos.TEXT_SIMPLU1.Valid
		*!*	modificare ROAGEST v 2.0.53
		*!*	If Val(This.Text)=0
		If Val(This.Text) = 0 Or Thisform.pretvtva = 0
		*!*	modificare ROAGEST v 2.0.53	^
			Thisform.do_executa()
		Endif
	ENDPROC

	PROCEDURE cmdTVA1.Click
		Thisform.AplicaTVA(this.Caption)
	ENDPROC

	PROCEDURE cmdTVA2.Click
		Thisform.AplicaTVA(this.Caption)
	ENDPROC

	PROCEDURE cmdTVA3.Click
		Thisform.AplicaTVA(this.Caption)
	ENDPROC

	PROCEDURE cmdTVA4.Click
		Thisform.AplicaTVA(this.Caption)
	ENDPROC

	PROCEDURE cmdTVA5.Click
		Thisform.AplicaTVA(this.Caption)
	ENDPROC

	PROCEDURE Image1.Click
		thisform.do_alege_reteta()
	ENDPROC

	PROCEDURE Item1.Text_item1.InteractiveChange
		If Thisform.proc_discount <> 0
			Thisform.cobj.Pret = Round(This.Value*(100-Thisform.proc_discount)/100,gnPpret)
		Else
			Thisform.cobj.Pret = This.Value
		Endif
		*!*	modificare	ROAFACTURARE v 2.2.20
		*!*	*!*	*!* CALCULEZ tva doar pentru seturile in afara de 231,234 (NIR mf pret de lista, NIR RATC)
		*!*	*!*	*!* la 231, 234 se ia pretul de pe ultimul NIR
		*!*	*!*	If !((poact.id_set = 231 or plNIRBONPretCuTVA) AND !Empty(Thisform.cobj.tva)) 
		*!*	Thisform.cobj.tva = Round(Thisform.cobj.Pret * (Thisform.cobj.proc_tva - 1),gnPpret)
		*!*	*!*	EndIf 	
		*!*	Thisform.item3.Refresh
			Thisform.calculeaza_tva_ach()
		*!*	modificare	ROAFACTURARE v 2.2.20	^
	ENDPROC

	PROCEDURE Item1.Text_item1.ProgrammaticChange
		If Thisform.proc_discount <> 0
			Thisform.cobj.Pret = Round(This.Value*(100-Thisform.proc_discount)/100,gnPpret)
		Else
			Thisform.cobj.Pret = This.Value
		Endif
		
		*!*	*!* CALCULEZ tva doar pentru seturile in afara de 231,234 (NIR mf pret de lista, NIR RATC)
		*!*	*!* la 231, 234 se ia pretul de pe ultimul NIR
		*!*	If !((poact.id_set = 231 or plNIRBONPretCuTVA) AND !Empty(Thisform.cobj.tva)) 
		*Thisform.cobj.tva = Round(Thisform.cobj.Pret * (Thisform.cobj.proc_tva - 1),gnPpret)
		*!*	EndIf 	
		Thisform.item3.Refresh
	ENDPROC

	PROCEDURE Item1.Text_item1.Valid
		*!*	modificare	ROAFACTURARE v 2.2.20
		*!*	Thisform.item4.text_item1.Valid()
		Thisform.calculeaza_valori_ach(Thisform.item4.text_item1.Value)
		*!*	modificare	ROAFACTURARE v 2.2.20	^
	ENDPROC

	PROCEDURE Item2.Text_item1.InteractiveChange
		If 'F' $ Thisform.bvizualizare
		*!*	modificare	ROAFACTURARE v 2.2.20
		*!*	*!*		If !((poact.id_set = 231 or plNIRBONPretCuTVA) AND !Empty(Thisform.cobj.tva)) 
		*!*			Thisform.cobj.tva = Round(Thisform.cobj.Pret * (Thisform.cobj.proc_tva - 1),gnPpret)
		*!*	*!*		EndIf 	
		*!*		Thisform.item3.Refresh
			Thisform.calculeaza_tva_ach()
		*!*	modificare	ROAFACTURARE v 2.2.20	^
		Endif
		
		If Thisform.cobj.procent <> 0 And !INLIST(oset.id_set, 105, 231, 247, 266) && procent adaos - Achizitie fact. neplatita- marfa la pret de vanzare/achizitie
			Thisform.do_executa  && calculeaza pretul de vanzare inclusiv Tva
		Endif
	ENDPROC

	PROCEDURE Item2.Text_item1.ProgrammaticChange
		If 'F' $ Thisform.bvizualizare
		*!*	modificare	ROAFACTURARE v 2.2.20
		*!*	*!*		If !((poact.id_set = 231 or plNIRBONPretCuTVA) AND !Empty(Thisform.cobj.tva)) 
		*!*			Thisform.cobj.tva = Round(Thisform.cobj.Pret * (Thisform.cobj.proc_tva - 1),gnPpret)
		*!*	*!*		EndIf 	
		*!*		Thisform.item3.Refresh
			Thisform.calculeaza_tva_ach()
		*!*	modificare	ROAFACTURARE v 2.2.20	^
		Endif
		
		If Thisform.cobj.procent <> 0 And !INLIST(oset.id_set, 105, 231, 247, 266) && procent adaos - Achizitie fact. neplatita- marfa la pret de vanzare/achizitie
			Thisform.do_executa  && calculeaza pretul de vanzare inclusiv Tva
		Endif
	ENDPROC

	PROCEDURE Item2.Text_item1.Valid
		If 'F' $ Thisform.bvizualizare
		*!*	modificare	ROAFACTURARE v 2.2.20
		*!*		Thisform.item4.text_item1.Valid()
			Thisform.calculeaza_valori_ach(Thisform.item4.text_item1.Value)
		*!*	modificare	ROAFACTURARE v 2.2.20	^
		EndIf 	
	ENDPROC

	PROCEDURE Item4.Text_item1.Valid
		*!*	modificare	ROAFACTURARE v 2.2.20
		*!*	Local lnCantitate, lnPret, lnTva, lnProcTva, lnValoareACTva, lnValoareATva, lnValoareACTva
		*!*	If !Thisform.blochezPretV AND poact.id_set <> 104 && (la imputare, sa ma lase sa pun cu mana pretv)
		*!*		Thisform.cobj.TVAV = Round(Thisform.PRETVTVA * (Thisform.cobj.proc_tvav-1)/Iif(Thisform.cobj.proc_tvav <> 0, Thisform.cobj.proc_tvav,1), gnPPretV)
		*!*		Thisform.cobj.PRETV = Thisform.PRETVTVA - Thisform.cobj.TVAV	
		*!*	Endif
		*!*	If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
		*!*		Thisform.cobj.procent=Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		*!*	Endif
		*!*	Thisform.item8.Refresh
		*!*	Thisform.item9.Refresh
		*!*	Thisform.clb_item_adaos.Refresh
		*!*	*!* v 2.0.24
		*!*	 
		*!*	lnCantitate = this.Value 
		*!*	lnPret = thisform.cobj.PRET
		*!*	lnTVA = thisform.cobj.TVA
		*!*	lnProcTVA = Iif(Thisform.cobj.PROC_TVA <> 0, Thisform.cobj.PROC_TVA, TVA2PROCTVA(lnTVA, lnPret))
		*!*	*!* in stoc nu exista coloana proc_tva !!! o calculez si o pun in rulaj
		*!*	Thisform.cobj.PROC_TVA = lnProcTva
		*!*	If !plNIRBONPretCuTVA
		*!*		lnValoareAFTva = Round(lnCantitate*lnPret, gnPC)
		*!*		lnValoareATva = Round(lnValoareAFTva * (lnProcTVA-1), gnPC)
		*!*		lnValoareACTva = lnValoareAFTva + lnValoareATva
		*!*	Else 
		*!*		lnValoareACTva = Round(lnCantitate*(lnPret+lnTVA), gnPC)
		*!*		lnValoareATva = Round(lnValoareACTva * (lnProcTva - 1) / lnProcTva, gnPC)
		*!*		lnValoareAFTva = lnValoareACTva - lnValoareATva
		*!*	EndIf 
		*!*	Thisform.valoare = lnValoareAFTva
		*!*	Thisform.VALOAREtva = lnValoareATva
		*!*	*!* v 2.0.24 ^
		*!*	Thisform.item5.Refresh
		*!*	Thisform.item6.Refresh
		Thisform.calculeaza_valori_ach(This.Value)
		*!*	modificare	ROAFACTURARE v 2.2.20	^
	ENDPROC

	PROCEDURE Item7.Text_item1.InteractiveChange
		Thisform.PRETVTVA = This.Value
		Thisform.cobj.PRETV = Round(Thisform.PRETVTVA / Thisform.cobj.proc_tvav, gnPPretV)
		Thisform.cobj.TVAV = Thisform.PRETVTVA - Thisform.cobj.PRETV
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent=Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		Thisform.item8.Refresh
		Thisform.item9.Refresh
		Thisform.clb_item_adaos.Refresh
	ENDPROC

	PROCEDURE Item7.Text_item1.Valid
		*!*	thisform.cobj.TVAV = ROUND(thisform.PRETVTVA * (thisform.cobj.proc_tvav-1)/thisform.cobj.proc_tvav, gnPpret)
		*!*	thisform.cobj.PRETV = thisform.PRETVTVA - thisform.cobj.TVAV
		
	ENDPROC

	PROCEDURE Item8.Text_item1.Valid
		*!*	*!*	thisform.cobj.TVAV = ROUND(thisform.cobj.PRETV*(thisform.cobj.proc_tvaV-1), gnPpret)
		*!*	Thisform.cobj.TVAV = Round(Thisform.cobj.PRETV*(Thisform.cobj.proc_tvaV-1), gnPc)
		*!*	Thisform.PRETVTVA = Thisform.cobj.PRETV + Thisform.cobj.TVAV
		*!*	If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
		*!*		Thisform.cobj.procent=Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		*!*	Endif
	ENDPROC

	PROCEDURE Item9.Text_item1.InteractiveChange
		*!* nu stiu de ce atunci cand mai trec prin cantitate si apoi in pret vanzare fara tva intra in interactivechange fara sa modific valoare
		If thisform.nPretvOriginal = This.Value
			Return
		EndIf 
		Thisform.cobj.PRETV = This.Value
		Thisform.cobj.TVAV = Round(Thisform.cobj.PRETV*(Thisform.cobj.proc_TVAV-1), gnPPretV)
		Thisform.PRETVTVA = Thisform.cobj.PRETV + Thisform.cobj.TVAV
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent = Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		Thisform.item7.Refresh
		Thisform.item8.Refresh
		Thisform.clb_item_adaos.Refresh
	ENDPROC

	PROCEDURE Item9.Text_item1.Valid
		*!*	thisform.cobj.TVAV = ROUND(thisform.cobj.PRETV*(thisform.cobj.proc_TVAV-1), gnPpret)
		
	ENDPROC

	PROCEDURE Item9.Text_item1.When
		thisform.nPretvOriginal = This.Value
	ENDPROC

	PROCEDURE Opt_imputare.Init
		pnImputare = this.Value
		
	ENDPROC

	PROCEDURE Opt_imputare.InteractiveChange
		pnImputare = this.Value
		
	ENDPROC

	PROCEDURE Opt_imputare.Valid
		pnImputare = this.Value
		
	ENDPROC

ENDDEFINE

DEFINE CLASS frm_introdnir_val AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Item2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item13" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item4" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item5" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item7" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item8" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item9" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item11" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item6" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_valuta_ach" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_explicatie_curs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item10" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Item12" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_valuta_vanz1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_valuta_vanz2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_valuta_vanz3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_valuta_ach_c" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_valuta_vanz_c" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_ITEM_adaos" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cbo_tva_vanzare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_tva_vanzare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="tx_curs_ach" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="tx_curs_vanz" UniqueID="" Timestamp="" />

	#INCLUDE "..\include\foxpro.h"
	*<DefinedPropArrayMethod>
		*m: do_modiparam
		*p: blochezpretv
		*p: cobj
		*p: cparentobj
		*p: ctitlu
		*p: ncant_iesita
		*p: ncant_stoc
		*p: ncursach
		*p: ncursvanz
		*p: omemopref
		*p: pretvtva
		*p: pretvtvaval
		*p: proc_adaos
		*p: proc_discount
		*p: proc_tvav
		*p: valoare
		*p: valoaretva
	*</DefinedPropArrayMethod>

	*<PropValue>
		bvizualizare = 
		cobj = 
		ctitlu = 
		DoCreate = .T.
		Height = 371
		Name = "frm_introdnir_val"
		ncant_iesita = .F.
		ncant_stoc = .F.
		ncursach = 0
		ncursvanz = 0
		omemopref = NULL
		pretvtva = 0
		pretvtvaval = 0
		proc_adaos = 0
		proc_discount = 0
		proc_tvav = 0
		valoare = 0
		valoaretva = 0
		Width = 634
		WindowType = 1
		_shape1.Height = 30
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = -1
		_shape1.Width = 636
		_shape1.ZOrderSet = 2
		_shape2.Height = 29
		_shape2.Left = 567
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 67
		_shape2.ZOrderSet = 3
		Lb_titlu_alb_b121.FontName = "Comic Sans MS"
		Lb_titlu_alb_b121.FontSize = 10
		Lb_titlu_alb_b121.Left = 8
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 17
		Lb_titlu_alb_b121.Top = 4
		Lb_titlu_alb_b121.ZOrderSet = 4
		BUT_TERMIN1.Left = 601
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 15
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 5
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 571, ;
		Name = "But_renunt1", ;
		TabIndex = 16, ;
		Top = 1, ;
		ZOrderSet = 6
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cbo_tva_vanzare' AS _combobox WITH ;
		BorderColor = 128,128,128, ;
		BorderStyle = 1, ;
		ColumnCount = 3, ;
		ColumnLines = .F., ;
		ColumnWidths = "200,10,0", ;
		Comment = "A", ;
		ControlSource = "", ;
		InputMask = "", ;
		Left = 475, ;
		Name = "cbo_tva_vanzare", ;
		RowSource = "jtva_vanzare.denumire,cota_tva,id_jtva_coloana", ;
		RowSourceType = 6, ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 26, ;
		TabStop = .F., ;
		Top = 261, ;
		Visible = .T., ;
		Width = 149
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="combobox" />

	ADD OBJECT 'Clb_ITEM_adaos' AS clb_tx_simplu WITH ;
		BorderColor = 255,255,255, ;
		Comment = "A", ;
		Height = 29, ;
		Left = 472, ;
		Name = "Clb_ITEM_adaos", ;
		TabIndex = 8, ;
		Top = 216, ;
		Width = 83, ;
		TEXT_SIMPLU1.Alignment = 1, ;
		TEXT_SIMPLU1.BackColor = 224,224,224, ;
		TEXT_SIMPLU1.BorderStyle = 0, ;
		TEXT_SIMPLU1.Comment = "thisform.cobj.procent", ;
		TEXT_SIMPLU1.ControlSource = "", ;
		TEXT_SIMPLU1.Height = 23, ;
		TEXT_SIMPLU1.InputMask = (get_mask(12,2)), ;
		TEXT_SIMPLU1.Left = 2, ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.SpecialEffect = 1, ;
		TEXT_SIMPLU1.Top = 2, ;
		TEXT_SIMPLU1.Width = 58, ;
		LB_SIMPLU1.Caption = "%", ;
		LB_SIMPLU1.FontName = "Comic Sans MS", ;
		LB_SIMPLU1.Left = 66, ;
		LB_SIMPLU1.Name = "LB_SIMPLU1", ;
		LB_SIMPLU1.Top = 5
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Item1' AS item WITH ;
		Comment = "T", ;
		Left = 13, ;
		Name = "Item1", ;
		TabIndex = 2, ;
		tip = F, ;
		Top = 67, ;
		ZOrderSet = 1, ;
		Label_item1.Caption = "Pret achizitie in valuta", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.pretd", ;
		Text_item1.InputMask = (get_mask(12,gnPpretVal)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item10' AS item WITH ;
		Comment = "A", ;
		Left = 13, ;
		Name = "Item10", ;
		TabIndex = 13, ;
		TabStop = .F., ;
		tip = A, ;
		Top = 309, ;
		ZOrderSet = 12, ;
		LABEL_ITEM1.Caption = "TVA vanzare in valuta", ;
		LABEL_ITEM1.Name = "LABEL_ITEM1", ;
		TEXT_ITEM1.Comment = "thisform.cobj.tvaval", ;
		TEXT_ITEM1.InputMask = (get_mask(12,gnPVal)), ;
		TEXT_ITEM1.Name = "TEXT_ITEM1", ;
		TEXT_ITEM1.ReadOnly = .T., ;
		LINEO1.Name = "LINEO1", ;
		LINEO3.Name = "LINEO3", ;
		LINEO4.Name = "LINEO4", ;
		LINEO5.Name = "LINEO5", ;
		LINEO2.Name = "LINEO2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item11' AS item WITH ;
		camp_lista = sectie, ;
		Comment = "T", ;
		fis_lista = Vnom_sectii, ;
		id_fisier = id_sectie, ;
		label_item = Denumire sectie, ;
		Left = 13, ;
		Name = "Item11", ;
		pcobj = orul, ;
		TabIndex = 7, ;
		TabStop = .F., ;
		tip = , ;
		Top = 189, ;
		ZOrderSet = 14, ;
		Label_item1.Caption = "Sectie", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.sectie", ;
		Text_item1.ControlSource = "", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item12' AS item WITH ;
		Comment = "X", ;
		Left = 13, ;
		Name = "Item12", ;
		TabIndex = 14, ;
		tip = A, ;
		Top = 332, ;
		ZOrderSet = 13, ;
		LABEL_ITEM1.Caption = "Pret de vanzare fara TVA", ;
		LABEL_ITEM1.Name = "LABEL_ITEM1", ;
		TEXT_ITEM1.Comment = "thisform.cobj.pretvval", ;
		TEXT_ITEM1.InputMask = (get_mask(14,gnPVal)), ;
		TEXT_ITEM1.Name = "TEXT_ITEM1", ;
		LINEO1.Name = "LINEO1", ;
		LINEO3.Name = "LINEO3", ;
		LINEO4.Name = "LINEO4", ;
		LINEO5.Name = "LINEO5", ;
		LINEO2.Name = "LINEO2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item13' AS item WITH ;
		Comment = "T", ;
		Left = 13, ;
		Name = "Item13", ;
		TabIndex = 1, ;
		tip = T, ;
		Top = 40, ;
		ZOrderSet = 1, ;
		Label_item1.Caption = "Serie", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.serie", ;
		Text_item1.Format = "K!", ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item2' AS item WITH ;
		Comment = "T", ;
		Left = 13, ;
		Name = "Item2", ;
		TabIndex = 3, ;
		tip = , ;
		Top = 90, ;
		ZOrderSet = 0, ;
		Label_item1.Caption = "Pret achizitie", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.pret", ;
		Text_item1.InputMask = (get_mask(12,gnPpret)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item3' AS item WITH ;
		Left = 13, ;
		Name = "Item3", ;
		TabIndex = 4, ;
		tip = F, ;
		Top = 114, ;
		ZOrderSet = 7, ;
		Label_item1.Caption = "Pret achizitie la cursul zilei", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.InputMask = (get_mask(12,gnPpret)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item4' AS item WITH ;
		Comment = "T", ;
		Left = 13, ;
		Name = "Item4", ;
		TabIndex = 5, ;
		tip = , ;
		Top = 138, ;
		ZOrderSet = 8, ;
		Label_item1.Caption = "Cantitate", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.cant", ;
		Text_item1.InputMask = (get_mask(12,gnPcant)), ;
		Text_item1.Name = "Text_item1", ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item5' AS item WITH ;
		Comment = "T", ;
		Left = 13, ;
		Name = "Item5", ;
		TabIndex = 6, ;
		tip = , ;
		Top = 162, ;
		ZOrderSet = 9, ;
		Label_item1.Caption = "Valoare ", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.valoare", ;
		Text_item1.InputMask = (get_mask(12,gnPc)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item6' AS item WITH ;
		Comment = "A", ;
		Left = 13, ;
		Name = "Item6", ;
		TabIndex = 12, ;
		tip = A, ;
		Top = 286, ;
		ZOrderSet = 11, ;
		LABEL_ITEM1.Caption = "Pret de vanzare cu TVA in valuta", ;
		LABEL_ITEM1.Name = "LABEL_ITEM1", ;
		TEXT_ITEM1.Comment = "thisform.Pretvtvaval", ;
		TEXT_ITEM1.InputMask = (get_mask(14,gnPVal)), ;
		TEXT_ITEM1.Name = "TEXT_ITEM1", ;
		LINEO1.Name = "LINEO1", ;
		LINEO3.Name = "LINEO3", ;
		LINEO4.Name = "LINEO4", ;
		LINEO5.Name = "LINEO5", ;
		LINEO2.Name = "LINEO2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item7' AS item WITH ;
		Comment = "A", ;
		Left = 13, ;
		Name = "Item7", ;
		TabIndex = 9, ;
		TabStop = .F., ;
		tip = A, ;
		Top = 216, ;
		ZOrderSet = 11, ;
		Label_item1.Caption = "Pret de vanzare cu TVA", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.PretvTva", ;
		Text_item1.InputMask = (get_mask(12,gnPPretV)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item8' AS item WITH ;
		Comment = "A", ;
		Left = 13, ;
		Name = "Item8", ;
		TabIndex = 10, ;
		TabStop = .F., ;
		tip = A, ;
		Top = 239, ;
		ZOrderSet = 12, ;
		Label_item1.Caption = "TVA vanzare", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.tvav", ;
		Text_item1.InputMask = (get_mask(12,gnPPretV)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'Item9' AS item WITH ;
		Comment = "X", ;
		Left = 13, ;
		Name = "Item9", ;
		TabIndex = 11, ;
		TabStop = .F., ;
		tip = A, ;
		Top = 262, ;
		ZOrderSet = 13, ;
		Label_item1.Caption = "Pret de vanzare fara TVA", ;
		Label_item1.Name = "Label_item1", ;
		Text_item1.Comment = "thisform.cobj.pretv", ;
		Text_item1.InputMask = (get_mask(12,gnPPretV)), ;
		Text_item1.Name = "Text_item1", ;
		Text_item1.ReadOnly = .T., ;
		Lineo1.Name = "Lineo1", ;
		Lineo3.Name = "Lineo3", ;
		Lineo4.Name = "Lineo4", ;
		Lineo5.Name = "Lineo5", ;
		Lineo2.Name = "Lineo2"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />

	ADD OBJECT 'lb_explicatie_curs' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Curs valutar", ;
		FontName = "Comic Sans MS", ;
		ForeColor = 0,0,128, ;
		Height = 20, ;
		Left = 488, ;
		Name = "lb_explicatie_curs", ;
		TabIndex = 18, ;
		Top = 107, ;
		Width = 75, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_tva_vanzare' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "TVA vanzare", ;
		Comment = "A", ;
		Height = 18, ;
		Left = 477, ;
		Name = "lb_tva_vanzare", ;
		TabIndex = 25, ;
		Top = 244, ;
		Visible = .T., ;
		Width = 75
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_valuta_ach' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "[Valuta]", ;
		Height = 18, ;
		Left = 474, ;
		Name = "lb_valuta_ach", ;
		TabIndex = 20, ;
		Top = 68, ;
		Width = 47, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_valuta_ach_c' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "[Valuta]", ;
		FontName = "Comic Sans MS", ;
		ForeColor = 0,0,128, ;
		Height = 20, ;
		Left = 482, ;
		Name = "lb_valuta_ach_c", ;
		TabIndex = 24, ;
		Top = 132, ;
		Width = 50, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_valuta_vanz1' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "[Valuta]", ;
		Left = 479, ;
		Name = "lb_valuta_vanz1", ;
		TabIndex = 21, ;
		Top = 287, ;
		Width = 47, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_valuta_vanz2' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "[Valuta]", ;
		Left = 479, ;
		Name = "lb_valuta_vanz2", ;
		TabIndex = 19, ;
		Top = 310, ;
		Width = 47, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_valuta_vanz3' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "[Valuta]", ;
		Left = 479, ;
		Name = "lb_valuta_vanz3", ;
		TabIndex = 23, ;
		Top = 333, ;
		Width = 47, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lb_valuta_vanz_c' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "[Valuta]", ;
		FontName = "Comic Sans MS", ;
		ForeColor = 0,0,128, ;
		Height = 20, ;
		Left = 482, ;
		Name = "lb_valuta_vanz_c", ;
		TabIndex = 22, ;
		Top = 156, ;
		Width = 50, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'tx_curs_ach' AS _txbase WITH ;
		Alignment = 0, ;
		BorderStyle = 0, ;
		ControlSource = "thisform.ncursach", ;
		FontName = "Comic Sans MS", ;
		Height = 18, ;
		InputMask = (get_mask(6,4)), ;
		Left = 540, ;
		Name = "tx_curs_ach", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		TabIndex = 27, ;
		TabStop = .F., ;
		Top = 132, ;
		Value = 0, ;
		Width = 84
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'tx_curs_vanz' AS _txbase WITH ;
		Alignment = 0, ;
		BorderStyle = 0, ;
		ControlSource = "thisform.ncursvanz", ;
		FontName = "Comic Sans MS", ;
		Height = 18, ;
		InputMask = (get_mask(6,4)), ;
		Left = 540, ;
		Name = "tx_curs_vanz", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		TabIndex = 28, ;
		TabStop = .F., ;
		Top = 156, ;
		Value = 0, ;
		Width = 84
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />
	
	PROCEDURE do_executa
		This.cobj.pretv = Round(This.cobj.Pret * (1 + This.cobj.procent/100), gnPPretV)
		This.cobj.TVAV = Round(This.cobj.pretv*(This.cobj.proC_TVAV-1), gnPPretV)
		This.PRETVTVA = This.cobj.pretv + This.cobj.TVAV
		This.item7.Refresh
		This.item8.Refresh
		This.item9.Refresh
		
		thisform.cobj.pretvval = Round(Thisform.cobj.pretv / thisform.cobj.curs,gnPVal)
		thisform.cobj.tvaval = Round(Thisform.cobj.TVAV / thisform.cobj.curs,gnPVal)
		Thisform.pretvtvaval = thisform.cobj.pretvval + thisform.cobj.tvaval
		Thisform.item6.Refresh
		Thisform.item10.Refresh
		Thisform.item12.Refresh
	ENDPROC

	PROCEDURE do_modiparam
	ENDPROC

	PROCEDURE inainte_de_do_termin
		*!* 27.05.2009 - cantitatea introdusa plus cantitatea iesita nu trebuie sa depaseasca cantitatea din stoc.
		*!* marius.felecanu
		Local llReturn
		Store .T. To llReturn
		IF thisform.ncant_stoc <> 0
		   IF thisform.ncant_iesita + thisform.item4.text_item1.Value > thisform.ncant_stoc 
			  AMESSAGEBOX("Cantitatea maxima existenta este: " + ALLTRIM(STR(thisform.ncant_stoc - thisform.ncant_iesita,18,4)),0+48,_screen.Caption)
			  llReturn = .F.
			  thisform.item4.SetFocus() 
			ENDIF 
		ENDIF 	 
		RETURN llReturn 
		*!* 27.05.2009 ^
	ENDPROC

	PROCEDURE Init
		LPARAMETERS toDatePref
		DODEFAULT()
		Thisform.omemopref = IIF(TYPE("toDatePref")="O",toDatePref,NULL)
		
	ENDPROC

	PROCEDURE Show
		Lparameters nStyle
		lnHeight = 0
		
		With Thisform.lb_explicatie_curs
			.Caption = [Curs valutar ] + Dtoc(poAct.v8)
			.AutoSize = .T.
		Endwith
		
		Select crscursuri
		If !Empty(Nvl(Thisform.cobj.id_valuta,0))
			Locate For id_valuta = Thisform.cobj.id_valuta
			If Found()
				Thisform.ncursach = Curs / multiplicator
				lcNumeValuta = Upper(Alltrim(nume_val))
				With Thisform.lb_valuta_ach
					.Caption = lcNumeValuta
					.AutoSize = .T.
				Endwith
				With Thisform.lb_valuta_ach_c
					.Caption = lcNumeValuta
					.AutoSize = .T.
				Endwith
			Endif
			Thisform.item3.text_item1.Value = Round(Thisform.cobj.pretd*Thisform.ncursach,gnPPret)
		Else
			Thisform.ncursach = 0
			Thisform.lb_valuta_ach.Visible = .F.
			Thisform.lb_valuta_ach_c.Visible = .F.
			Thisform.tx_curs_ach.Visible = .F.
			Thisform.item1.Visible = .F.
			Thisform.item3.Visible = .F.
			Thisform.lb_valuta_vanz_c.Top = Thisform.lb_valuta_ach_c.Top
			Thisform.tx_curs_vanz.Top = Thisform.tx_curs_ach.Top
		Endif
		
		If Nvl(Thisform.cobj.id_valuta,0) <> poAct.id_valuta_vanz
			*!*		Locate For id_valuta = poAct.id_valuta_vanz
			*!*		If Found()
			*!*			Thisform.ncursvanz = Curs
			*!*			lcNumeValuta = Upper(Alltrim(nume_val))
			Thisform.ncursvanz = Thisform.cobj.Curs
			lcNumeValuta = poAct.nume_val_vanz
			*!*		Endif
		Else
			Thisform.lb_valuta_vanz_c.Visible = .F.
			Thisform.tx_curs_vanz.Visible = .F.
		Endif
		With Thisform.lb_valuta_vanz1
			.Caption = lcNumeValuta
			.AutoSize = .T.
		Endwith
		With Thisform.lb_valuta_vanz2
			.Caption = lcNumeValuta
			.AutoSize = .T.
		Endwith
		With Thisform.lb_valuta_vanz3
			.Caption = lcNumeValuta
			.AutoSize = .T.
		Endwith
		With Thisform.lb_valuta_vanz_c
			.Caption = lcNumeValuta
			.AutoSize = .T.
		Endwith
		
		Thisform.proc_adaos = 0
		
		For Each loControl In This.Controls
			With loControl
				If !Empty(loControl.Comment)
					If .Comment $ This.bVizualizare
						.Visible = .T.
						If 'ITEM' $ Upper(.Name)
							For Each loCtrSecund In loControl.Controls
								If 'TEXT' $ Upper(loCtrSecund.Name)
									lcControlSource = Alltrim(loCtrSecund.Comment)
									loCtrSecund.ControlSource = lcControlSource
								Endif
							Endfor
							*!*						lcControlSource = ALLTRIM(.text_item1.comment)
							*!*						.text_item1.controlsource = lcControlSource
							.pcobj = 'orul'
						Endif
						lnTop = .Top
						If lnTop > lnHeight
							lnHeight = lnTop
						Endif
					Else
						.Visible = .F.
					Endif
				Endif
			Endwith
		Endfor
		
		If gnNeplatitoare_tva = 1
			*!*	modificare 21.02.2007
			Select jtva_achizitie
			Locate For id_jtva_coloana = 113
			If Found()
				This.cbo_tva_achizitie.Value = Alltrim(denumire)
				Thisform.cobj.id_jtva_coloana = id_jtva_coloana
				This.cobj.proc_tva = (cota_tva + 100)/100
			Endif
			Select jtva_vanzare
			Locate For id_jtva_coloana = 11
			If Found()
				This.cbo_tva_VANZARE.Value = Alltrim(denumire)
				Thisform.cobj.PROC_TVAv = (jtva_vanzare.cota_tva + 100)/100
				Thisform.PROC_TVAv = (jtva_vanzare.cota_tva + 100)/100
				If !('F' $ This.bVizualizare)
					This.cobj.id_jtva_coloana = id_jtva_coloana
				Endif
			Endif
			*!*		SELECT cote_tva
			*!*		LOCATE FOR proc_tva = 1.00
			*!*		IF !FOUND()
			*!*			SELECT cote_tva
			*!*			GO TOP
			*!*		ENDIF
			*!*	modificare 21.02.2007	^
		Else
			*!*	modificare 21.02.2007
			Select jtva_achizitie
			Do Case
				Case This.cobj.Cont = '371' And oset.id_jtax =	141		&&	taxare inversa 19 %
					Locate For id_jtva_coloana = 139
				Case This.cobj.Cont = '371'	And oset.id_jtax =	105		&&	marfa 19 %
					Locate For id_jtva_coloana = 103
				Otherwise
					Locate For id_jtva_coloana = oset.id_jtax or id_jtva_ex = oset.id_jtax	&&	modificare v 2.2.0 : conditia de dupa or
			Endcase
			If Found()
				This.cbo_tva_achizitie.Value = Alltrim(denumire)
				Thisform.cobj.id_jtva_coloana = id_jtva_coloana
				This.cobj.proc_tva = (cota_tva + 100)/100
			Endif
			*!*		SELECT cote_tva
			*!*		GO TOP
			*!*	modificare 21.02.2007 ^
		Endif
		
		If 'F' $ This.bVizualizare And Empty(This.cobj.proc_tva)
			*!*	modificare 21.02.2007
			Select jtva_achizitie
			Do Case
				Case This.cobj.Cont = '371' And oset.id_jtax =	141		&&	taxare inversa 19 %
					Locate For id_jtva_coloana = 139
				Case This.cobj.Cont = '371'	And oset.id_jtax =	105		&&	marfa 19 %
					Locate For id_jtva_coloana = 103
				Otherwise
					Locate For id_jtva_coloana = oset.id_jtax or id_jtva_ex = oset.id_jtax	&&	modificare v 2.2.0 : conditia de dupa or
			Endcase
			If Found()
				This.cbo_tva_achizitie.Value = Alltrim(denumire)
				Thisform.cobj.id_jtva_coloana = id_jtva_coloana
				This.cobj.proc_tva = (cota_tva + 100)/100
			Endif
			*!*		SELECT cote_tva
			*!*		* GO top
			*!*		lnProc_tva = proc_tva
			*!*		lnproc = procent
			*!*		THIS.cotaTVA_achizitie.VALUE = ALLTRIM(STR(lnproc))
			*!*		THIS.cobj.proc_tva = lnProc_tva
			*!*	modificare 21.02.2007 ^
		Endif
		
		If 'A' $ This.bVizualizare
			If This.blochezPretV
				This.item7.Enabled = .F.
				This.item8.Enabled = .F.
				This.item9.Enabled = .F.
				This.Clb_ITEM_adaos.Visible = .F.
				*!*	modificare 21.02.2007
				lcFiltru = [cota_tva = ] + Alltrim(Str(Thisform.cobj.PROC_TVAv * 100 - 100))
				Select jtva_vanzare
				Set Filter To &lcFiltru
				Go Top
				This.cbo_tva_VANZARE.Value = Alltrim(denumire)
				If !('F' $ This.bVizualizare)
					This.cobj.id_jtva_coloana = id_jtva_coloana
				Endif
				*!*			THIS.CotaTVA_vanzare.ENABLED = .F.
				*!*			THIS.CotaTVA_vanzare.VALUE = ALLTRIM(STR(THIS.proc_tvav *100 - 100))
				*!*	modificare 21.02.2007	^
			Else
				*!*	modificare 21.02.2007
				Select jtva_vanzare
				Locate For id_jtva_coloana = Iif(oset.tipjurnal=[JV],oset.id_jtax,GetIdJtvaStandard('VANZARE')) or id_jtva_ex = Iif(oset.tipjurnal=[JV],oset.id_jtax,GetIdJtvaStandard('VANZARE'))	&&	modificare v 2.2.0 : conditia de dupa or
				If Found()
					This.cbo_tva_VANZARE.Value = Alltrim(denumire)
					This.cobj.PROC_TVAv = (cota_tva + 100)/100
					If !('F' $ This.bVizualizare)
						This.cobj.id_jtva_coloana = id_jtva_coloana
					Endif
				Endif
				*!*			SELECT cote_tva
				*!*			* GO top
				*!*			lnProc_tva = proc_tva
				*!*			lnproc = procent
				*!*			THIS.CotaTVA_vanzare.VALUE = ALLTRIM(STR(lnproc))
				*!*			THIS.cobj.proc_tvav = lnProc_tva
				*!*	modificare 21.02.2007 ^
			Endif
		
			This.cobj.procent = Thisform.proc_adaos
		Endif
		
		This.lb_titlu_alb_b121.Caption = This.cTitlu
		This.item4.SetFocus
		
		*!*	modificare ROAFACTURARE	v 2.0.90
		If Thisform.ncursach <> Round(Thisform.ncursach,4)
			Thisform.tx_curs_ach.InputMask = get_mask(8,6)
		Endif
		If Thisform.ncursvanz <> Round(Thisform.ncursvanz,4)
			Thisform.tx_curs_vanz.InputMask = get_mask(8,6)
		Endif
		*!*	modificare ROAFACTURARE	v 2.0.90	^
		DoDefault()
		
	ENDPROC

	PROCEDURE cbo_tva_vanzare.Valid
		If !('F' $ Thisform.bVizualizare)
			Thisform.COBJ.id_jtva_coloana = jtva_vanzare.id_jtva_coloana
		Endif
		If !Thisform.blochezPretV
			Thisform.COBJ.PROC_TVAv = (jtva_vanzare.cota_tva + 100)/100
			Thisform.PROC_TVAv = (jtva_vanzare.cota_tva + 100)/100
			Thisform.item7.teXT_ITEM1.InteractiveChange
		Endif
	ENDPROC

	PROCEDURE Clb_ITEM_adaos.TEXT_SIMPLU1.Valid
		thisform.do_executa 
	ENDPROC

	PROCEDURE Item12.TEXT_ITEM1.InteractiveChange
		thisform.cobj.pretvval = This.Value
		thisform.cobj.tvaval = Round(thisform.cobj.pretvval * (Thisform.cobj.proc_tvav-1),gnPVal)
		Thisform.pretvtvaval = thisform.cobj.pretvval + thisform.cobj.tvaval
		Thisform.item6.Refresh
		Thisform.item10.Refresh
		
		Thisform.cobj.PRETV = Round(thisform.cobj.pretvval * thisform.cobj.curs , gnPPretV)
		Thisform.cobj.TVAV = Round(thisform.cobj.tvaval * thisform.cobj.curs, gnPPretV)
		Thisform.PRETVTVA = Thisform.cobj.PRETV + Thisform.cobj.TVAV
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent = Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		Thisform.item7.Refresh
		Thisform.item8.Refresh
		Thisform.item9.Refresh
		Thisform.clb_item_adaos.Refresh
	ENDPROC

	PROCEDURE Item4.Text_item1.Valid
		If !Thisform.blochezPretV AND poact.id_set <> 104 && (la imputare, sa ma lase sa pun cu mana pretv)
		*!*		thisform.cobj.TVAV = ROUND(thisform.PRETVTVA * (thisform.cobj.proc_tvav-1)/IIF(thisform.cobj.proc_tvav <> 0, thisform.cobj.proc_tvav,1), gnPpret)
			Thisform.cobj.TVAV = Round(Thisform.PRETVTVA * (Thisform.cobj.proc_tvav-1)/Iif(Thisform.cobj.proc_tvav <> 0, Thisform.cobj.proc_tvav,1), gnPPretV)
			Thisform.cobj.PRETV = Thisform.PRETVTVA - Thisform.cobj.TVAV
		Endif
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent=Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		Thisform.item8.Refresh
		Thisform.item9.Refresh
		Thisform.clb_item_adaos.Refresh
		
		
		Thisform.valoare = Round(This.Value * Thisform.cobj.Pret,gnPc)
		Thisform.VALOAREtva = Round(Thisform.valoare*(Thisform.cobj.PROC_TVA-1),gnPc)
		Thisform.item5.Refresh
		Thisform.item6.Refresh
	ENDPROC

	PROCEDURE Item6.TEXT_ITEM1.InteractiveChange
		Thisform.pretvtvaval = This.Value
		thisform.cobj.pretvval = Round(Thisform.pretvtvaval / Thisform.cobj.proc_tvav,gnPVal)
		thisform.cobj.tvaval = Thisform.pretvtvaval - thisform.cobj.pretvval
		Thisform.item10.Refresh
		Thisform.item12.Refresh
		
		Thisform.PRETVTVA = Round(Thisform.pretvtvaval * thisform.cobj.curs, gnPPretV)
		Thisform.cobj.PRETV = Round(thisform.cobj.pretvval * thisform.cobj.curs, gnPPretV)
		Thisform.cobj.TVAV = Thisform.PRETVTVA - Thisform.cobj.PRETV
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent=Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		Thisform.item7.Refresh
		Thisform.item8.Refresh
		Thisform.item9.Refresh
		Thisform.clb_item_adaos.Refresh
	ENDPROC

	PROCEDURE Item6.TEXT_ITEM1.Valid
		*!*	thisform.cobj.TVAV = ROUND(thisform.PRETVTVA * (thisform.cobj.proc_tvav-1)/thisform.cobj.proc_tvav, gnPpret)
		*!*	thisform.cobj.PRETV = thisform.PRETVTVA - thisform.cobj.TVAV
		
	ENDPROC

	PROCEDURE Item7.Text_item1.InteractiveChange
		Thisform.PRETVTVA = This.Value
		Thisform.cobj.PRETV = Round(Thisform.PRETVTVA / Thisform.cobj.proc_tvav, gnPPretV)
		Thisform.cobj.TVAV = Thisform.PRETVTVA - Thisform.cobj.PRETV
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent=Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		Thisform.item8.Refresh
		Thisform.item9.Refresh
		Thisform.clb_item_adaos.Refresh
		
		Thisform.pretvtvaval = Round(Thisform.PRETVTVA / thisform.cobj.curs,gnPVal)
		thisform.cobj.pretvval	= Round(Thisform.cobj.PRETV / thisform.cobj.curs,gnPVal)
		thisform.cobj.tvaval = Thisform.pretvtvaval - thisform.cobj.pretvval
		Thisform.item6.Refresh
		Thisform.item10.Refresh
		Thisform.item12.Refresh
	ENDPROC

	PROCEDURE Item9.Text_item1.InteractiveChange
		Thisform.cobj.PRETV = This.Value
		Thisform.cobj.TVAV = Round(Thisform.cobj.PRETV*(Thisform.cobj.proc_TVAV-1), gnPPretV)
		Thisform.PRETVTVA = Thisform.cobj.PRETV + Thisform.cobj.TVAV
		If !Empty(Thisform.cobj.Pret) And !Empty(Thisform.cobj.PRETV)
			Thisform.cobj.procent = Round((Thisform.cobj.PRETV/Thisform.cobj.Pret-1)*100, gnPc)
		Endif
		
		Thisform.item7.Refresh
		Thisform.item8.Refresh
		Thisform.clb_item_adaos.Refresh
		
		thisform.cobj.pretvval	= Round(Thisform.cobj.PRETV / thisform.cobj.curs,gnPVal)
		thisform.cobj.tvaval = Round(Thisform.cobj.TVAV / thisform.cobj.curs,gnPVal)
		Thisform.pretvtvaval = thisform.cobj.pretvval + thisform.cobj.tvaval
		Thisform.item6.Refresh
		Thisform.item10.Refresh
		Thisform.item12.Refresh
	ENDPROC

ENDDEFINE

DEFINE CLASS import_adauga_factura AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="shpDvi" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_shape3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_shape4" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblFelDoc" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtFelDoc" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdFelDoc" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblSerie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtSerie" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblNr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtNr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblData" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtData" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblPartener" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtPartener" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdPartener" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_label1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtFelDocDVI" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblSuma" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtSuma" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblValuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtValuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdValuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblCurs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtCurs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="chkParticipaValuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="chkInValutaCont" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="optTipTva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_label2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblExplicatieTva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtExplicatieTva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdExplicatieTva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblPedagogieDvi" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDviNr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtDviNr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDviData" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtDviData" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDviPartener" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtDviPartener" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdDviPartener" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDviTvaVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtDviTvaVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblProcentTva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtProcentTva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdFelDocDVI" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDviValuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtDviValuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdDviValuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDviCurs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtDviCurs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDiscBaza" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txtDiscBaza" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="chkDviInValuta" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: actualizeaza_etichete_sume
		*m: actualizeaza_stare_dvi
		*m: actualizeaza_stare_dvi_valuta
		*m: actualizeaza_stare_valuta
		*m: arata_valuta_curs
		*m: construieste_todlg
		*m: dvi_curs_efectiv
		*m: dvi_id_valuta_efectiva
		*m: dvi_tva_in_valuta
		*m: dvi_valuta_efectiva
		*m: recalc_tva
		*m: seteaza_masti
		*m: tva_dvi_lei
		*m: valideaza
		*p: cdvipartener
		*p: cdviserie
		*p: cdvivaluta
		*p: cexplicatia
		*p: cexplicatietva
		*p: cfeldoc
		*p: cfeldocdvi
		*p: cpartener
		*p: cserieact
		*p: cseriedvi
		*p: cvaluta
		*p: ddata
		*p: ddataact
		*p: ddvidata
		*p: lcursdirty
		*p: ldvicursdirty
		*p: ldviinvalutadirty
		*p: ldvitvavaldirty
		*p: ldvivalutadirty
		*p: linvalutadirty		&& bifa "in valuta" schimbata explicit de utilizator - nu o mai fortez
		*p: lsuprimadirty
		*p: ncurs
		*p: ndiscbaza
		*p: ndvicurs
		*p: ndvicursoldval
		*p: ndviidpartener
		*p: ndviidvaluta
		*p: ndvitvalei
		*p: ndvitvaval
		*p: ndvitvavaloldval
		*p: nidexplicatietva
		*p: nidfdoc
		*p: nidfdocdvi
		*p: nidpartener
		*p: nidvaluta
		*p: nnract
		*p: nnractdvi
		*p: noldval
		*p: nprocenttva
		*p: nsuma
		*p: nsumalei		&& suma fara TVA in lei (calculata din suma si curs)
		*p: oparinte		&& referinta catre import_nota care a deschis dialogul
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		cdvipartener = ""
		cdviserie = ""
		cdvivaluta = ""
		cexplicatia = ""
		cexplicatietva = ""
		cfeldoc = ""
		cfeldocdvi = ""
		cpartener = ""
		cserieact = ""
		cseriedvi = ""
		cvaluta = ""
		ddata = {}
		ddataact = {}
		ddvidata = {}
		DoCreate = .T.
		Height = 410
		lcursdirty = .F.
		ldvicursdirty = .F.
		ldviinvalutadirty = .F.
		ldvitvavaldirty = .F.
		ldvivalutadirty = .F.
		linvalutadirty = .F.
		lsuprimadirty = .F.
		Name = "import_adauga_factura"
		ncurs = 0
		ndiscbaza = 0
		ndvicurs = 0
		ndvicursoldval = 0
		ndviidpartener = 0
		ndviidvaluta = 0
		ndvitvalei = 0
		ndvitvaval = 0
		ndvitvavaloldval = 0
		nidexplicatietva = 0
		nidfdoc = 0
		nidfdocdvi = 0
		nidpartener = 0
		nidvaluta = 0
		nnract = 0
		nnractdvi = 0
		noldval = 0
		nprocenttva = 0
		nsuma = 0
		nsumalei = 0
		oparinte = 
		Width = 655
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 653
		_shape1.ZOrderSet = 3
		_shape2.Left = 586
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.ZOrderSet = 4
		Lb_titlu_alb_b121.Caption = "Adauga factura"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.ZOrderSet = 5
		BUT_TERMIN1.Left = 623
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 30
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.Visible = .T.
		BUT_TERMIN1.ZOrderSet = 6
		Gridsort1.Left = 5
		Gridsort1.Name = "Gridsort1"
		Gridsort1.Top = 31
	*</PropValue>

	ADD OBJECT '_label1' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Fel doc", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 20, ;
		Name = "_label1", ;
		Top = 280, ;
		Width = 50, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT '_label2' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "completati TVA% si apoi alegeti Explicatie TVA", ;
		FontBold = .F., ;
		FontItalic = .T., ;
		FontSize = 9, ;
		Height = 17, ;
		Left = 20, ;
		Name = "_label2", ;
		Top = 227, ;
		Width = 257, ;
		ZOrderSet = 32
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT '_shape3' AS _shape WITH ;
		BackColor = 240,225,255, ;
		BackStyle = 0, ;
		Height = 131, ;
		Left = 7, ;
		Name = "_shape3", ;
		SpecialEffect = 0, ;
		Top = 36, ;
		Width = 639, ;
		ZOrderSet = 1
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT '_shape4' AS _shape WITH ;
		BackColor = 197,197,226, ;
		BackStyle = 0, ;
		Height = 83, ;
		Left = 7, ;
		Name = "_shape4", ;
		SpecialEffect = 0, ;
		Top = 165, ;
		Width = 639, ;
		ZOrderSet = 2
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Left = 593, ;
		Name = "But_renunt1", ;
		TabIndex = 31, ;
		Top = 1, ;
		ZOrderSet = 47
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'chkDviInValuta' AS _checkbox WITH ;
		Alignment = 0, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Valuta", ;
		Height = 18, ;
		Left = 300, ;
		Name = "chkDviInValuta", ;
		TabIndex = 29, ;
		TabStop = .F., ;
		Top = 364, ;
		Value = 0, ;
		Width = 56, ;
		ZOrderSet = 63
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'chkInValutaCont' AS _checkbox WITH ;
		Alignment = 0, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Valuta", ;
		Height = 18, ;
		Left = 560, ;
		Name = "chkInValutaCont", ;
		TabIndex = 13, ;
		TabStop = .F., ;
		Top = 133, ;
		Value = 1, ;
		Width = 55, ;
		WordWrap = .T., ;
		ZOrderSet = 30
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'chkParticipaValuta' AS _checkbox WITH ;
		Alignment = 0, ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Participa la pretul de intrare", ;
		Height = 34, ;
		Left = 529, ;
		Name = "chkParticipaValuta", ;
		TabIndex = 14, ;
		TabStop = .F., ;
		Top = 66, ;
		Value = 1, ;
		Width = 107, ;
		WordWrap = .T., ;
		ZOrderSet = 29
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'cmdDviPartener' AS _commandbutton WITH ;
		Caption = "...", ;
		Enabled = .F., ;
		FontBold = .T., ;
		FontName = "Arial", ;
		Left = 496, ;
		Name = "cmdDviPartener", ;
		TabIndex = 24, ;
		Top = 305, ;
		Width = 24, ;
		ZOrderSet = 42
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdDviValuta' AS _commandbutton WITH ;
		Caption = "...", ;
		Enabled = .F., ;
		FontBold = .T., ;
		FontName = "Arial", ;
		Left = 206, ;
		Name = "cmdDviValuta", ;
		TabIndex = 27, ;
		Top = 361, ;
		Width = 18, ;
		ZOrderSet = 54
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdExplicatieTva' AS _commandbutton WITH ;
		Caption = "...", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		Left = 475, ;
		Name = "cmdExplicatieTva", ;
		TabIndex = 18, ;
		Top = 200, ;
		Width = 24, ;
		ZOrderSet = 34
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdFelDoc' AS _commandbutton WITH ;
		Caption = "...", ;
		FontBold = .T., ;
		Left = 223, ;
		Name = "cmdFelDoc", ;
		TabIndex = 2, ;
		Top = 38, ;
		Width = 24, ;
		ZOrderSet = 10
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdFelDocDVI' AS _commandbutton WITH ;
		Caption = "...", ;
		FontBold = .T., ;
		Left = 230, ;
		Name = "cmdFelDocDVI", ;
		TabIndex = 20, ;
		Top = 275, ;
		Width = 24, ;
		ZOrderSet = 10
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdPartener' AS _commandbutton WITH ;
		Caption = "...", ;
		FontBold = .T., ;
		Height = 21, ;
		Left = 490, ;
		Name = "cmdPartener", ;
		TabIndex = 7, ;
		Top = 70, ;
		Width = 24, ;
		ZOrderSet = 19
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdValuta' AS _commandbutton WITH ;
		Caption = "...", ;
		FontBold = .T., ;
		Left = 440, ;
		Name = "cmdValuta", ;
		TabIndex = 11, ;
		Top = 129, ;
		Width = 24, ;
		ZOrderSet = 26
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'lblCurs' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Curs", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 472, ;
		Name = "lblCurs", ;
		Top = 111, ;
		Width = 30, ;
		ZOrderSet = 27
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblData' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Data", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 494, ;
		Name = "lblData", ;
		Top = 43, ;
		Width = 30, ;
		ZOrderSet = 15
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDiscBaza' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Discount", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 190, ;
		Name = "lblDiscBaza", ;
		Top = 111, ;
		Width = 56, ;
		ZOrderSet = 59
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDviCurs' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Curs", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 234, ;
		Name = "lblDviCurs", ;
		Top = 345, ;
		Width = 30, ;
		ZOrderSet = 55
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDviData' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Data", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 453, ;
		Name = "lblDviData", ;
		Top = 279, ;
		Width = 31, ;
		ZOrderSet = 38
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDviNr' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Nr", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 263, ;
		Name = "lblDviNr", ;
		Top = 279, ;
		Width = 16, ;
		ZOrderSet = 36
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDviPartener' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Partener", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 20, ;
		Name = "lblDviPartener", ;
		Top = 310, ;
		Width = 57, ;
		ZOrderSet = 40
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDviTvaVal' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "TVA valuta", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 20, ;
		Name = "lblDviTvaVal", ;
		Top = 345, ;
		Width = 71, ;
		ZOrderSet = 43
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDviValuta' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Valuta", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 150, ;
		Name = "lblDviValuta", ;
		Top = 345, ;
		Width = 43, ;
		ZOrderSet = 52
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblExplicatieTva' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Explicatie TVA", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 118, ;
		Name = "lblExplicatieTva", ;
		Top = 205, ;
		Width = 95, ;
		ZOrderSet = 32
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblFelDoc' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Fel doc", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 15, ;
		Name = "lblFelDoc", ;
		Top = 43, ;
		Width = 50, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblNr' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Nr", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 345, ;
		Name = "lblNr", ;
		Top = 43, ;
		Width = 20, ;
		ZOrderSet = 13
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblPartener' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Partener", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 15, ;
		Name = "lblPartener", ;
		Top = 73, ;
		Width = 60, ;
		ZOrderSet = 17
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblPedagogieDvi' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "DVI", ;
		FontBold = .T., ;
		ForeColor = 0,0,25, ;
		Height = 18, ;
		Left = 20, ;
		Name = "lblPedagogieDvi", ;
		Top = 254, ;
		Width = 24, ;
		ZOrderSet = 35
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblProcentTva' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "TVA %", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 18, ;
		Name = "lblProcentTva", ;
		Top = 205, ;
		Width = 42, ;
		ZOrderSet = 48
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblSerie' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Serie", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 255, ;
		Name = "lblSerie", ;
		Top = 43, ;
		Width = 34, ;
		ZOrderSet = 11
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblSuma' AS _label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Suma fara TVA", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 15, ;
		Name = "lblSuma", ;
		Top = 111, ;
		Width = 98, ;
		ZOrderSet = 22
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblValuta' AS _label WITH ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Valuta", ;
		FontBold = .T., ;
		Height = 17, ;
		Left = 366, ;
		Name = "lblValuta", ;
		Top = 111, ;
		Width = 40, ;
		ZOrderSet = 24
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'optTipTva' AS _optiongrup WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		ButtonCount = 3, ;
		Height = 28, ;
		Left = 16, ;
		Name = "optTipTva", ;
		TabIndex = 15, ;
		Top = 171, ;
		Value = 1, ;
		Width = 289, ;
		ZOrderSet = 31, ;
		Option1.AutoSize = .T., ;
		Option1.BackStyle = 0, ;
		Option1.Caption = "TVA Furnizor", ;
		Option1.FontBold = .T., ;
		Option1.FontSize = 10, ;
		Option1.Height = 18, ;
		Option1.Left = 5, ;
		Option1.Name = "Option1", ;
		Option1.Top = 5, ;
		Option1.Width = 102, ;
		Option2.AutoSize = .T., ;
		Option2.BackStyle = 0, ;
		Option2.Caption = "TVA DVI", ;
		Option2.FontBold = .T., ;
		Option2.FontSize = 10, ;
		Option2.Height = 18, ;
		Option2.Left = 116, ;
		Option2.Name = "Option2", ;
		Option2.Top = 5, ;
		Option2.Width = 71, ;
		Option3.AutoSize = .T., ;
		Option3.BackStyle = 0, ;
		Option3.Caption = "Fara TVA", ;
		Option3.FontBold = .T., ;
		Option3.FontSize = 10, ;
		Option3.Height = 18, ;
		Option3.Left = 206, ;
		Option3.Name = "Option3", ;
		Option3.Top = 5, ;
		Option3.Width = 78
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="optiongroup" />

	ADD OBJECT 'shpDvi' AS _shape WITH ;
		BackColor = 217,217,236, ;
		BackStyle = 1, ;
		Height = 158, ;
		Left = 7, ;
		Name = "shpDvi", ;
		SpecialEffect = 0, ;
		Top = 247, ;
		Width = 639, ;
		ZOrderSet = 0
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT 'txtCurs' AS _textbox WITH ;
		Alignment = 1, ;
		ControlSource = "Thisform.nCurs", ;
		Format = "RK", ;
		InputMask = "9999.9999", ;
		Left = 472, ;
		Name = "txtCurs", ;
		TabIndex = 12, ;
		Top = 131, ;
		Width = 80, ;
		ZOrderSet = 28
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtData' AS _textbox WITH ;
		ControlSource = "Thisform.dDataAct", ;
		Format = "K", ;
		Left = 528, ;
		Name = "txtData", ;
		TabIndex = 5, ;
		Top = 40, ;
		Width = 94, ;
		ZOrderSet = 16
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtDiscBaza' AS _textbox WITH ;
		Alignment = 1, ;
		ControlSource = "Thisform.nDiscBaza", ;
		Format = "RK", ;
		Height = 23, ;
		InputMask = "9999999999.9999", ;
		Left = 190, ;
		Name = "txtDiscBaza", ;
		TabIndex = 9, ;
		Top = 131, ;
		Width = 114, ;
		ZOrderSet = 60
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtDviCurs' AS _textbox WITH ;
		Alignment = 1, ;
		ControlSource = "Thisform.nDviCurs", ;
		Enabled = .F., ;
		Format = "RK", ;
		Height = 23, ;
		InputMask = "9999.9999", ;
		Left = 234, ;
		Name = "txtDviCurs", ;
		TabIndex = 28, ;
		Top = 363, ;
		Width = 55, ;
		ZOrderSet = 56
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtDviData' AS _textbox WITH ;
		ControlSource = "Thisform.dDviData", ;
		Enabled = .F., ;
		Format = "K", ;
		Left = 493, ;
		Name = "txtDviData", ;
		TabIndex = 22, ;
		Top = 277, ;
		Width = 90, ;
		ZOrderSet = 39
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtDviNr' AS _textbox WITH ;
		ControlSource = "Thisform.nNractDvi", ;
		Enabled = .F., ;
		Format = "RK", ;
		Height = 23, ;
		InputMask = "9999999999", ;
		Left = 288, ;
		Name = "txtDviNr", ;
		TabIndex = 21, ;
		Top = 277, ;
		Width = 147, ;
		ZOrderSet = 37
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtDviPartener' AS _textbox WITH ;
		ControlSource = "Thisform.cDviPartener", ;
		Enabled = .F., ;
		Format = "K", ;
		Height = 23, ;
		Left = 93, ;
		Name = "txtDviPartener", ;
		TabIndex = 23, ;
		Top = 307, ;
		Width = 400, ;
		ZOrderSet = 41
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtDviTvaVal' AS _textbox WITH ;
		Alignment = 1, ;
		ControlSource = "Thisform.nDviTvaVal", ;
		Enabled = .F., ;
		Format = "RK", ;
		Height = 23, ;
		InputMask = "9999999.9999", ;
		Left = 21, ;
		Name = "txtDviTvaVal", ;
		TabIndex = 25, ;
		Top = 363, ;
		Width = 112, ;
		ZOrderSet = 44
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtDviValuta' AS _textbox WITH ;
		ControlSource = "Thisform.cDviValuta", ;
		Enabled = .F., ;
		Format = "K", ;
		Height = 23, ;
		Left = 150, ;
		Name = "txtDviValuta", ;
		ReadOnly = .T., ;
		TabIndex = 26, ;
		Top = 363, ;
		Width = 52, ;
		ZOrderSet = 53
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtExplicatieTva' AS _textbox WITH ;
		ControlSource = "Thisform.cExplicatieTva", ;
		Enabled = .T., ;
		Format = "K", ;
		Left = 215, ;
		Name = "txtExplicatieTva", ;
		ReadOnly = .T., ;
		TabIndex = 17, ;
		Top = 202, ;
		Width = 254, ;
		ZOrderSet = 33
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtFelDoc' AS _textbox WITH ;
		ControlSource = "Thisform.cFelDoc", ;
		Enabled = .T., ;
		Format = "K", ;
		Left = 69, ;
		Name = "txtFelDoc", ;
		ReadOnly = .T., ;
		TabIndex = 1, ;
		Top = 40, ;
		Width = 150, ;
		ZOrderSet = 9
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtFelDocDVI' AS _textbox WITH ;
		ControlSource = "Thisform.cFelDocDVI", ;
		Enabled = .T., ;
		Format = "K", ;
		Left = 76, ;
		Name = "txtFelDocDVI", ;
		ReadOnly = .T., ;
		TabIndex = 19, ;
		Top = 277, ;
		Width = 150, ;
		ZOrderSet = 9
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtNr' AS _textbox WITH ;
		ControlSource = "Thisform.nNract", ;
		Format = "RK", ;
		Height = 23, ;
		InputMask = "9999999999", ;
		Left = 366, ;
		Name = "txtNr", ;
		TabIndex = 4, ;
		Top = 40, ;
		Width = 120, ;
		ZOrderSet = 14
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtPartener' AS _textbox WITH ;
		ControlSource = "Thisform.cPartener", ;
		Enabled = .T., ;
		Format = "K", ;
		Height = 23, ;
		Left = 87, ;
		Name = "txtPartener", ;
		ReadOnly = .T., ;
		TabIndex = 6, ;
		Top = 70, ;
		Width = 400, ;
		ZOrderSet = 18
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtProcentTva' AS _textbox WITH ;
		Alignment = 1, ;
		ControlSource = "Thisform.nProcentTva", ;
		Format = "RK", ;
		InputMask = "999.99", ;
		Left = 62, ;
		Name = "txtProcentTva", ;
		TabIndex = 16, ;
		Top = 202, ;
		Width = 44, ;
		ZOrderSet = 49
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtSerie' AS _textbox WITH ;
		ControlSource = "Thisform.cSerieAct", ;
		Format = "K", ;
		Height = 23, ;
		Left = 293, ;
		Name = "txtSerie", ;
		TabIndex = 3, ;
		Top = 40, ;
		Width = 44, ;
		ZOrderSet = 12
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtSuma' AS _textbox WITH ;
		Alignment = 1, ;
		ControlSource = "Thisform.nSuma", ;
		Format = "RK", ;
		Height = 23, ;
		InputMask = "9999999999.9999", ;
		Left = 15, ;
		Name = "txtSuma", ;
		TabIndex = 8, ;
		Top = 131, ;
		Width = 114, ;
		ZOrderSet = 23
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'txtValuta' AS _textbox WITH ;
		ControlSource = "Thisform.cValuta", ;
		Enabled = .T., ;
		Format = "K", ;
		Left = 366, ;
		Name = "txtValuta", ;
		ReadOnly = .T., ;
		TabIndex = 10, ;
		Top = 131, ;
		Width = 70, ;
		ZOrderSet = 25
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />
	
	PROCEDURE actualizeaza_etichete_sume
		*!* Etichetele sumelor arata moneda in care se tasteaza: valuta documentului cand
		*!* bifa "Valuta" e pusa, altfel RON; TVA-ul DVI urmeaza bifa lui.
		Local lcVal, lcValDvi
		lcVal = Iif(This.chkInValutaCont.Value = 1 And This.nCurs <> 0 And !(Empty(Nvl(This.cValuta, '')) Or Upper(Alltrim(Nvl(This.cValuta, ''))) == 'RON'), Alltrim(This.cValuta), 'RON')
		lcValDvi = Iif(This.dvi_tva_in_valuta(), Alltrim(This.dvi_valuta_efectiva()), 'RON')
		This.lblSuma.Caption = 'Valoare fara TVA ' + lcVal
		This.lblDiscBaza.Caption = 'Discount fara TVA ' + lcVal
		This.lblDviTvaVal.Caption = 'Valoare TVA ' + lcValDvi
		This.Refresh()
	ENDPROC

	PROCEDURE actualizeaza_stare_dvi
		*!* Arata/ascunde subrandul DVI dupa radio-ul TVA; pre-completeaza din memoria DVI
		*!* a lui import_nota si pune data DVI = data facturii principale daca lipseste.
		Local llDvi, loCtl
		llDvi = (This.optTipTva.Value = 2)
		For Each loCtl In This.Controls
			If At('DVI', Upper(loCtl.Name)) > 0
				loCtl.Visible = llDvi
				If Pemstatus(loCtl, 'Enabled', 5)
					loCtl.Enabled = llDvi
				Endif
			Endif
		Endfor
		This._label1.Visible = llDvi
		If llDvi
			If !Empty(This.oParinte.cDviSerie) Or This.oParinte.nDviIdPartener <> 0 Or !Empty(Nvl(This.oParinte.nDviIdFdoc, 0)) Or Val(Nvl(This.oParinte.cDviNr, '0')) <> 0
				This.cDviSerie = This.oParinte.cDviSerie
				This.cDviPartener = This.oParinte.cDviPartener
				This.dDviData = This.oParinte.dDviData
				This.nDviIdPartener = This.oParinte.nDviIdPartener
				This.nNractDvi = Val(Nvl(This.oParinte.cDviNr, '0'))
				This.cFelDocDvi = Nvl(This.oParinte.cDviFelDoc, '')
				This.nIdFdocDVI = Nvl(This.oParinte.nDviIdFdoc, 0)
			Endif
			If Vartype(This.dDviData) <> 'D' Or Empty(This.dDviData)
				This.dDviData = This.dDataAct
			Endif
			This.txtDviNr.Value = This.nNractDvi
			This.txtDviData.Value = This.dDviData
			This.txtDviPartener.Value = This.cDviPartener
		Endif
		This.actualizeaza_stare_dvi_valuta()
		This.Refresh()
	ENDPROC

	PROCEDURE actualizeaza_stare_dvi_valuta
		*!* Resincronizeaza bifa cu starea valutei facturii daca n-a fost schimbata manual.
		*!* Bifa scoasa = DVI fara valuta proprie: ascunde valuta/cursul, curs=1, TVA tastat in lei.
		If This.optTipTva.Value <> 2
			Return
		Endif
		If !This.lDviInValutaDirty
			This.chkDviInValuta.Value = Iif(This.chkInValutaCont.Value = 1 And !(Empty(This.cValuta) Or Upper(Alltrim(This.cValuta)) == 'RON'), 1, 0)
		Endif
		This.lblDviValuta.Visible = (This.chkDviInValuta.Value = 1)
		This.txtDviValuta.Visible = (This.chkDviInValuta.Value = 1)
		This.cmdDviValuta.Visible = (This.chkDviInValuta.Value = 1)
		If This.dvi_tva_in_valuta()
			This.lblDviCurs.Visible = .T.
			This.txtDviCurs.Visible = .T.
			This.txtDviCurs.Enabled = .T.
		Else
			This.lblDviCurs.Visible = .F.
			This.txtDviCurs.Visible = .F.
			This.txtDviCurs.Enabled = .F.
			This.nDviCurs = 1
			This.txtDviCurs.Value = 1
			This.lDviCursDirty = .F.
		Endif
		This.seteaza_masti()
		This.actualizeaza_etichete_sume()
		This.Refresh()
	ENDPROC

	PROCEDURE actualizeaza_stare_valuta
		*!* Propune cursul BNR (onom_curs.vc2 / clasa "curs") pentru valuta si data curente.
		*!* Daca valuta e RON, cursul e fixat la 1 si nu se mai cere suma in valuta.
		*!* Daca utilizatorul a editat manual cursul (lCursDirty), nu il mai suprascriu.
		Local loCurs, lnCurs
		If Empty(This.cValuta) Or Upper(Alltrim(This.cValuta)) == 'RON'
			This.nCurs = 1
			This.txtCurs.Value = 1
		
			This.txtCurs.Enabled = .F.
			This.chkInValutaCont.Value = 0
			This.chkInValutaCont.Enabled = .F.
			This.arata_valuta_curs(.T.)
		Else
			This.txtCurs.Enabled = .T.
			This.chkInValutaCont.Enabled = .T.
			If !This.lInValutaDirty
				This.chkInValutaCont.Value = 1
			Endif
			This.arata_valuta_curs(This.chkInValutaCont.Value = 1)
		Endif
		This.seteaza_masti()
		This.Refresh()
	ENDPROC

	PROCEDURE arata_valuta_curs
		*!* Arata/ascunde selectorul de valuta si cursul (bifa "Suma in valuta in contabilitate").
		Lparameters tlArata
		This.lblValuta.Visible = tlArata
		This.txtValuta.Visible = tlArata
		This.cmdValuta.Visible = tlArata
		This.lblCurs.Visible = tlArata
		This.txtCurs.Visible = tlArata
	ENDPROC

	PROCEDURE construieste_todlg
		*!* Construieste obiectul toDlg cu datele dialogului, pentru import_nota.do_adauga_factura().
		Local loT, lcDviVal, lcFactVal, llDviFaraVal, llFactFaraVal, llDviPropriu
		loT = Createobject('Empty')
		Addproperty(loT, 'serie_act', Alltrim(Nvl(This.cSerieAct, '')))
		Addproperty(loT, 'nract', This.nNract)
		Addproperty(loT, 'dataact', This.dDataAct)
		Addproperty(loT, 'fdoc', This.cFelDoc)
		Addproperty(loT, 'id_fdoc', This.nIdFdoc)
		Addproperty(loT, 'id_partc', This.nIdPartener)
		Addproperty(loT, 'partc', This.cPartener)
		Addproperty(loT, 'explicatia', Alltrim(Nvl(This.cExplicatia, '')))
		Addproperty(loT, 'suma', Iif(This.chkInValutaCont.Value = 1 And This.nCurs <> 0, Round(This.nSuma * This.nCurs, m.gnPC), This.nSuma))
		Addproperty(loT, 'suma_val', Iif(This.chkInValutaCont.Value = 1 And This.nCurs <> 0, This.nSuma, 0))
		Addproperty(loT, 'in_valuta', This.chkInValutaCont.Value)
		Addproperty(loT, 'participa_valuta', (This.chkParticipaValuta.Value = 1))
		Addproperty(loT, 'id_valuta', Iif(This.chkInValutaCont.Value = 1, This.nIdValuta, 0))
		Addproperty(loT, 'curs', Iif(This.chkInValutaCont.Value = 1, This.nCurs, 0))
		Addproperty(loT, 'nume_val', Iif(This.chkInValutaCont.Value = 1, Alltrim(Nvl(This.cValuta, '')), ''))
		Addproperty(loT, 'cTipTva', Iif(This.optTipTva.Value = 1, 'F', Iif(This.optTipTva.Value = 2, 'D', 'N')))
		Addproperty(loT, 'id_jtva_coloana', This.nIdExplicatieTva)
		If This.optTipTva.Value = 2
			lcDviVal = Alltrim(Nvl(This.dvi_valuta_efectiva(), ''))
			lcFactVal = Alltrim(Nvl(This.cValuta, ''))
			llDviFaraVal = (This.chkDviInValuta.Value = 0) Or Empty(lcDviVal) Or Upper(lcDviVal) == 'RON'
			llFactFaraVal = (Empty(lcFactVal) Or Upper(lcFactVal) == 'RON')
			llDviPropriu = (This.dvi_id_valuta_efectiva() <> This.nIdValuta Or This.dvi_curs_efectiv() <> This.nCurs)
			Addproperty(loT, 'dvi_serie', Chrtran(Alltrim(Nvl(This.cSerieDvi, '')), Chr(34), ''))
			Addproperty(loT, 'dvi_nract', This.nNractDvi)
			Addproperty(loT, 'dvi_dataact', This.dDviData)
			Addproperty(loT, 'dvi_id_fdoc', This.nIdFdocDVI)
			Addproperty(loT, 'dvi_fdoc', This.cFelDocDvi)
			Addproperty(loT, 'dvi_id_partc', This.nDviIdPartener)
			Addproperty(loT, 'dvi_partc', This.cDviPartener)
			Addproperty(loT, 'dvi_scc', '401')
			Addproperty(loT, 'dvi_tva_lei', This.tva_dvi_lei())
			Addproperty(loT, 'dvi_tva_val', Iif(llDviFaraVal, 0, This.nDviTvaVal))
			Addproperty(loT, 'dvi_in_valuta', !llDviFaraVal)
			Addproperty(loT, 'dvi_id_valuta', This.dvi_id_valuta_efectiva())
			Addproperty(loT, 'dvi_curs', This.dvi_curs_efectiv())
			Addproperty(loT, 'dvi_nume_val', lcDviVal)
			Addproperty(loT, 'dvi_valuta_proprie', Iif(llDviFaraVal And llFactFaraVal, 0, Iif(llDviFaraVal <> llFactFaraVal, 1, Iif(llDviPropriu, 1, 0))))
		Endif
		Addproperty(loT, 'disc_baza_lei', Iif(This.chkInValutaCont.Value = 1 And This.nCurs <> 0, Round(This.nDiscBaza * This.nCurs, m.gnPC), This.nDiscBaza))
		Addproperty(loT, 'disc_baza_val', Iif(This.chkInValutaCont.Value = 1 And This.nCurs <> 0, This.nDiscBaza, 0))
		Return loT
	ENDPROC

	PROCEDURE dvi_curs_efectiv
		Return Iif(This.lDviValutaDirty Or This.lDviCursDirty, This.nDviCurs, This.nCurs)
	ENDPROC

	PROCEDURE dvi_id_valuta_efectiva
		Return Iif(This.lDviValutaDirty, This.nDviIdValuta, This.nIdValuta)
	ENDPROC

	PROCEDURE dvi_tva_in_valuta
		*!* .T. cand TVA-ul DVI se tasteaza in valuta (bifa pusa si valuta efectiva nu e RON).
		Return This.chkDviInValuta.Value = 1 And !(Empty(This.dvi_valuta_efectiva()) Or Upper(Alltrim(This.dvi_valuta_efectiva())) == 'RON')
	ENDPROC

	PROCEDURE dvi_valuta_efectiva
		Return Iif(This.lDviValutaDirty, This.cDviValuta, This.cValuta)
	ENDPROC

	PROCEDURE inainte_de_do_termin
		*!* Hook _frmbase apelat de do_termin: valideaza si adauga perechea baza+TVA prin
		*!* import_nota.do_adauga_factura(). Return .F. tine dialogul deschis pentru corectare.
		Local loFelDviCauta, llOk
		
		If !Thisform.valideaza()
			Return .F.
		Endif
		
		* la prima trecere pe "prin DVI" cer felul documentului DVI - devine cheia
		* memoriei DVI pentru restul sesiunii
		If Thisform.optTipTva.Value = 2 And Empty(Nvl(Thisform.nIdFdocDVI, 0)) And Empty(Alltrim(Nvl(Thisform.cFelDocDvi, '')))
			loFelDviCauta = caut_fdoc(.F., .T.)
			If Vartype(loFelDviCauta) <> 'O' Or Empty(Nvl(loFelDviCauta.id_fdoc, 0))
				Amessagebox('Alegeti felul documentului pentru DVI.', 0 + 48, 'Adauga factura')
				Return .F.
			Endif
			Thisform.oParinte.nDviIdFdoc = loFelDviCauta.id_fdoc
			Thisform.nIdFdocDVI = loFelDviCauta.id_fdoc
			Thisform.cFelDocDvi = loFelDviCauta.fel_document
			Thisform.oParinte.cDviFelDoc = loFelDviCauta.fel_document
		Endif
		
		Thisform.LockScreen = .T.
		Wait Window 'Se adauga factura...' Nowait
		llOk = Thisform.oParinte.do_adauga_factura(Thisform.construieste_todlg())
		Wait Clear
		
		If llOk And Thisform.optTipTva.Value = 2
			* memoria DVI (identitate document) traieste pe import_nota
			Thisform.oParinte.cDviSerie = Chrtran(Alltrim(Nvl(Thisform.cSerieDvi, '')), Chr(34), '')
			Thisform.oParinte.cDviNr = Alltrim(Str(Thisform.nNractDvi, 14))
			Thisform.oParinte.dDviData = Thisform.dDviData
			Thisform.oParinte.nDviIdPartener = Thisform.nDviIdPartener
			Thisform.oParinte.cDviPartener = Thisform.cDviPartener
			Thisform.oParinte.cDviFelDoc = Thisform.cFelDocDvi
			Thisform.oParinte.nDviIdFdoc = Thisform.nIdFdocDVI
		Endif
		
		Thisform.LockScreen = .F.
		Return llOk
	ENDPROC

	PROCEDURE Init
		Lparameters toParinte
		
		DoDefault()
		
		This.oParinte = toParinte
		This.dData = Iif(Vartype(toParinte.oact.dataact) = 'D' And !Empty(toParinte.oact.dataact), toParinte.oact.dataact, Date())
		This.dDataAct = This.dData
		This.nIdValuta = Nvl(toParinte.oact.id_valuta, 0)
		This.cValuta = Alltrim(Nvl(toParinte.oact.nume_val, ''))
		This.nCurs = Nvl(toParinte.oact.curs, 1)
		This.nDviIdValuta = This.nIdValuta
		This.cDviValuta = This.cValuta
		This.nDviCurs = This.nCurs
		This.cExplicatia = ''
		
		* pre-completare din antetul notei (toParinte.oact = Scatter din vact); campurile raman
		* editabile. Type() acopera cazul in care un camp lipseste din vact.
		If Type('toParinte.oact.id_fdoc') <> 'U'
			This.nIdFdoc = Nvl(toParinte.oact.id_fdoc, 0)
			This.cFelDoc = Alltrim(Nvl(toParinte.oact.fdoc, ''))
		Endif
		If Type('toParinte.oact.id_partc') <> 'U'
			This.nIdPartener = Nvl(toParinte.oact.id_partc, 0)
			This.cPartener = Alltrim(Nvl(toParinte.oact.partc, ''))
		Endif
		If Type('toParinte.oact.serie_act') <> 'U'
			This.cSerieAct = Alltrim(Nvl(toParinte.oact.serie_act, ''))
		Endif
		
		* memoria DVI, daca a mai fost folosita in aceasta sesiune a formularului import_nota
		This.cDviSerie = toParinte.cDviSerie
		This.cDviPartener = toParinte.cDviPartener
		This.dDviData = toParinte.dDviData
		This.nDviIdPartener = toParinte.nDviIdPartener
		This.cFelDocDvi = Nvl(toParinte.cDviFelDoc, '')
		This.nIdFdocDVI = Nvl(toParinte.nDviIdFdoc, 0)
		This.nNractDvi = Val(Nvl(toParinte.cDviNr, '0'))
		
		* explicatia TVA default: iau din randul 1 (baza) al perechii - baza defineste
		* documentul (ex. "Ach. CE"); randul 2 e TVA ("TVA Ach. CE"). Daca introdc e goala
		* (prima factura) iau din introdc_sablon, altfel din prima pereche din introdc.
		Local lnSelIni
		lnSelIni = Select()
		This.nIdExplicatieTva = 0
		This.cExplicatieTva = ''
		This.nProcentTva = 0
		If Used('introdc') And Reccount('introdc') >= 2
			Select introdc
			Go TOP 
			This.nIdExplicatieTva = Nvl(id_jtva_coloana, 0)
			This.cExplicatieTva = Alltrim(Nvl(explicatie_tva, ''))
			This.nProcentTva = Nvl(ptva, 0)
		Else
			If Used('introdc_sablon') And Reccount('introdc_sablon') >= 2
				Select introdc_sablon
				Go TOP 
				This.nIdExplicatieTva = Nvl(id_jtva_coloana, 0)
				This.cExplicatieTva = Alltrim(Nvl(explicatie_tva, ''))
				This.nProcentTva = Nvl(ptva, 0)
			Endif
		Endif
		Select (lnSelIni)
		
		This.optTipTva.Value = 1
		This.actualizeaza_stare_valuta()
		This.actualizeaza_stare_dvi()
		This.actualizeaza_etichete_sume()
		This.Refresh()
	ENDPROC

	PROCEDURE recalc_tva
		*!* Precompleteaza TVA-ul DVI din baza neta (suma - discount) si cota (This.nProcentTva).
		*!* Campul de TVA se tasteaza in valuta DVI cand DVI-ul are valuta, altfel in lei.
		Local lnCota, lnTvaVal, lnTvaLei, lnDiscLei, lnDiscVal, lnBazaLeiNet, lnBazaValNet
		lnCota = Nvl(This.nProcentTva, 0)
		If This.chkInValutaCont.Value = 1 And This.nCurs <> 0
			This.nSumaLei = Round(This.nSuma * This.nCurs, m.gnPC)
		Else
			This.nSumaLei = Round(This.nSuma, m.gnPC)
		Endif
		If This.optTipTva.Value = 2 And lnCota > 0 And This.nSuma <> 0
			lnDiscLei = Iif(This.chkInValutaCont.Value = 1 And This.nCurs <> 0, Round(This.nDiscBaza * This.nCurs, m.gnPC), This.nDiscBaza)
			lnDiscVal = Iif(This.chkInValutaCont.Value = 1 And This.nCurs <> 0, This.nDiscBaza, 0)
			lnBazaLeiNet = This.nSumaLei - lnDiscLei
			lnBazaValNet = This.nSuma - lnDiscVal
			If !This.dvi_tva_in_valuta()
				lnTvaLei = Round(lnBazaLeiNet * lnCota / 100, m.gnPC)
				lnTvaVal = 0
			Else
				If This.chkInValutaCont.Value = 1 And This.nCurs <> 0 And This.dvi_id_valuta_efectiva() == This.nIdValuta
					lnTvaVal = Round(lnBazaValNet * lnCota / 100, m.gnPval)
				Else
					lnTvaLei = Round(lnBazaLeiNet * lnCota / 100, m.gnPC)
					lnTvaVal = Iif(This.dvi_curs_efectiv() <> 0, Round(lnTvaLei / This.dvi_curs_efectiv(), m.gnPval), 0)
				Endif
			Endif
			If !This.lDviTvaValDirty
				This.nDviTvaVal = Iif(This.dvi_tva_in_valuta(), lnTvaVal, lnTvaLei)
				This.txtDviTvaVal.Value = This.nDviTvaVal
			Endif
		Else
			If !This.lDviTvaValDirty
				This.nDviTvaVal = 0
				This.txtDviTvaVal.Value = 0
			Endif
		Endif
		This.nDviTvaLei = This.tva_dvi_lei()
	ENDPROC

	PROCEDURE seteaza_masti
		*!* Masti de precizie pe sumele din dialog: valorile in valuta cu m.gnPval,
		*!* valorile in lei cu m.gnPC - acelasi mecanism ca in grid (get_mask).
		Local llValuta
		llValuta = (This.chkInValutaCont.Value = 1 And This.nCurs <> 0)
		This.txtSuma.InputMask = get_mask(12, Iif(llValuta, m.gnPval, m.gnPC))
		This.txtDiscBaza.InputMask = get_mask(12, Iif(llValuta, m.gnPval, m.gnPC))
		This.txtDviTvaVal.InputMask = get_mask(12, Iif(This.dvi_tva_in_valuta(), m.gnPval, m.gnPC))
	ENDPROC

	PROCEDURE tva_dvi_lei
		*!* TVA-ul DVI in lei, din valoarea tastata (in valuta DVI sau direct in lei).
		Return Iif(This.dvi_tva_in_valuta(), Round(This.nDviTvaVal * This.dvi_curs_efectiv(), m.gnPC), Round(This.nDviTvaVal, m.gnPC))
	ENDPROC

	PROCEDURE valideaza
		*!* Validari la "Termin": mesaj explicit per camp lipsa, Return .F. opreste inchiderea.
		If Empty(Nvl(This.nIdFdoc, 0)) And Empty(Alltrim(Nvl(This.cFelDoc, '')))
			Amessagebox('Alegeti felul documentului.', 0 + 48, 'Adauga factura')
			Return .F.
		Endif
		If This.nNract = 0
			Amessagebox('Completati numarul actului.', 0 + 48, 'Adauga factura')
			Return .F.
		Endif
		If Vartype(This.dDataAct) <> 'D' Or Empty(This.dDataAct)
			Amessagebox('Completati data documentului.', 0 + 48, 'Adauga factura')
			Return .F.
		Endif
		If Year(This.dDataAct) <> m.gnAn Or Month(This.dDataAct) <> m.gnLuna
			Amessagebox('Data documentului nu este in perioada de lucru (' + Alltrim(Str(m.gnLuna)) + '/' + Alltrim(Str(m.gnAn)) + ').', 0 + 48, 'Adauga factura')
			Return .F.
		Endif
		If Empty(Nvl(This.nIdPartener, 0))
			Amessagebox('Alegeti partenerul.', 0 + 48, 'Adauga factura')
			Return .F.
		Endif
		If This.nSuma = 0
			Amessagebox('Suma nu poate fi zero.', 0 + 48, 'Adauga factura')
			Return .F.
		Endif
		If This.optTipTva.Value = 1 And Empty(Nvl(This.nIdExplicatieTva, 0))
			Amessagebox('Alegeti explicatia TVA.', 0 + 48, 'Adauga factura')
			Return .F.
		Endif
		If This.optTipTva.Value = 2
			If This.nNractDvi = 0 Or Vartype(This.dDviData) <> 'D' Or Empty(This.dDviData)
				Amessagebox('Completati numarul si data DVI-ului.', 0 + 48, 'Adauga factura')
				Return .F.
			Endif
			If Empty(Nvl(This.nDviIdPartener, 0))
				Amessagebox('Alegeti partenerul vamal (DVI).', 0 + 48, 'Adauga factura')
				Return .F.
			Endif
			If This.chkDviInValuta.Value = 1 And !(Empty(This.dvi_valuta_efectiva()) Or Upper(Alltrim(This.dvi_valuta_efectiva())) == 'RON') And This.dvi_curs_efectiv() = 0
				Amessagebox('Completati cursul valutei DVI.', 0 + 48, 'Adauga factura')
				Return .F.
			Endif
			If This.tva_dvi_lei() = 0
				Amessagebox('Valoarea TVA (DVI) trebuie sa fie mai mare decat zero.', 0 + 48, 'Adauga factura')
				Return .F.
			Endif
		Endif
		If This.nDiscBaza <> 0
			If This.nDiscBaza < 0
				Amessagebox('Discountul nu poate fi negativ.', 0 + 48, 'Adauga factura')
				Return .F.
			Endif
			If This.nDiscBaza >= This.nSuma
				Amessagebox('Discountul este mai mare sau egal cu suma facturii. Verificati valoarea.', 0 + 48, 'Adauga factura')
				Return .F.
			Endif
		Endif
		Return .T.
	ENDPROC

	PROCEDURE chkDviInValuta.InteractiveChange
		Thisform.lDviInValutaDirty = .T.
		Thisform.lDviTvaValDirty = .F.
		Thisform.actualizeaza_stare_dvi_valuta()
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE chkInValutaCont.InteractiveChange
		*!* bifa scoasa = suma NU se inregistreaza in valuta: valuta si cursul nu au sens,
		*!* le ascund; valorile raman memorate pe forma si revin la re-bifare.
		Thisform.lInValutaDirty = .T.
		Thisform.lDviTvaValDirty = .F.
		Thisform.arata_valuta_curs(This.Value = 1)
		Thisform.seteaza_masti()
		Thisform.actualizeaza_stare_dvi_valuta()
		Thisform.recalc_tva()
		Thisform.actualizeaza_etichete_sume()
	ENDPROC

	PROCEDURE cmdDviPartener.Click
		Local loCauta
		loCauta = caut_partener(-2, 'Alegeti partenerul DVI', .F., .T., .T., Thisform.dDataAct)
		If Vartype(loCauta) = 'O' And !Empty(Nvl(loCauta.id_part, 0))
			Thisform.nDviIdPartener = loCauta.id_part
			Thisform.cDviPartener = Alltrim(loCauta.denumire)
			Thisform.txtDviPartener.Refresh()
		Endif
	ENDPROC

	PROCEDURE cmdDviValuta.Click
		Local loCauta
		loCauta = caut_valuta(, .F., .F.)
		If Vartype(loCauta) = 'O' And !Empty(Nvl(loCauta.id_valuta, 0))
			Thisform.nDviIdValuta = loCauta.id_valuta
			Thisform.cDviValuta = Alltrim(loCauta.nume_val)
			Thisform.txtDviValuta.Refresh()
			Thisform.lDviCursDirty = .F.
			Thisform.lDviValutaDirty = .T.
			Thisform.lDviTvaValDirty = .F.
			Thisform.actualizeaza_stare_dvi_valuta()
			Thisform.recalc_tva()
		Endif
	ENDPROC

	PROCEDURE cmdExplicatieTva.Click
		*!* Cauta explicatia TVA filtrata dupa procentul ales (Thisform.nProcentTva) - acelasi
		*!* mecanism ca in grid (do_modifica_explicatie_tva): cauta_alfa direct pe vjtva_coloane
		*!* cu filtru pe cota_tva. Procent 0/gol => toate cotele.
		Local loCauta, lnCota, lcFiltru
		lnCota = Nvl(Thisform.nProcentTva, 0)
		lcFiltru = [id_jtva_coloana > 0]
		If lnCota > 0
			lcFiltru = lcFiltru + [ and cota_tva = ] + Alltrim(Str(lnCota, 10, 2))
		Endif
		loCauta = cauta_alfa([select id_jtva_coloana, denumire, cota_tva FROM vjtva_coloane], [1=2], [], ;
			[denumire], [denumire,cota_tva], [Alegeti explicatia TVA], [Explicatie TVA,Cota TVA], ;
			[], .F., lcFiltru)
		If Vartype(loCauta) <> 'O' Or Empty(Nvl(loCauta.id_jtva_coloana, 0))
			Return
		Endif
		Thisform.nIdExplicatieTva = loCauta.id_jtva_coloana
		Thisform.cExplicatieTva = Alltrim(loCauta.denumire)
		Thisform.nProcentTva = Nvl(loCauta.cota_tva, 0)
		Thisform.txtExplicatieTva.Refresh()
		If Pemstatus(Thisform, 'txtProcentTva', 5)
			Thisform.txtProcentTva.Refresh()
		Endif
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE cmdFelDoc.Click
		Local loCauta
		loCauta = caut_fdoc(.F., .T.)
		If Vartype(loCauta) = 'O' And !Empty(Nvl(loCauta.id_fdoc, 0))
			Thisform.nIdFdoc = loCauta.id_fdoc
			Thisform.cFelDoc = loCauta.fel_document
			Thisform.txtFelDoc.Refresh()
			Thisform.txtSerie.SetFocus()
		Endif
	ENDPROC

	PROCEDURE cmdFelDocDVI.Click
		Local loCauta
		loCauta = caut_fdoc(.F., .T.)
		If Vartype(loCauta) = 'O' And !Empty(Nvl(loCauta.id_fdoc, 0))
			Thisform.nIdFdocDVI = loCauta.id_fdoc
			Thisform.cFelDocDVI = loCauta.fel_document
			Thisform.txtFelDocDVI.Refresh()
			Thisform.txtDVINr.SetFocus()
		Endif
	ENDPROC

	PROCEDURE cmdPartener.Click
		Local loCauta
		loCauta = caut_partener(-2, 'Alegeti furnizorul', .F., .T., .T., Thisform.dDataAct)
		If Vartype(loCauta) = 'O' And !Empty(Nvl(loCauta.id_part, 0))
			Thisform.nIdPartener = loCauta.id_part
			Thisform.cPartener = Alltrim(loCauta.denumire)
			Thisform.txtPartener.Refresh()
			Thisform.txtSuma.SetFocus()
		Endif
	ENDPROC

	PROCEDURE cmdValuta.Click
		Local loCauta
		loCauta = caut_valuta(, .F., .F.)
		If Vartype(loCauta) = 'O' And !Empty(Nvl(loCauta.id_valuta, 0))
			Thisform.nIdValuta = loCauta.id_valuta
			Thisform.cValuta = Alltrim(loCauta.nume_val)
			Thisform.txtValuta.Refresh()
			Thisform.lCursDirty = .F.
			Thisform.lInValutaDirty = .F.
			Thisform.lDviTvaValDirty = .F.
			Thisform.actualizeaza_stare_valuta()
			If !Thisform.lDviValutaDirty
				Thisform.nDviIdValuta = Thisform.nIdValuta
				Thisform.cDviValuta = Thisform.cValuta
				Thisform.nDviCurs = Thisform.nCurs
				Thisform.txtDviValuta.Refresh()
				Thisform.txtDviCurs.Refresh()
			Endif
			Thisform.actualizeaza_stare_dvi_valuta()
			Thisform.actualizeaza_etichete_sume()
			Thisform.recalc_tva()
		Endif
	ENDPROC

	PROCEDURE optTipTva.InteractiveChange
		Thisform.actualizeaza_stare_dvi()
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE txtCurs.Valid
		If !Thisform.lSuprimaDirty
			Thisform.lCursDirty = .T.
		Endif
		Thisform.nCurs = This.Value
		If !Thisform.lDviValutaDirty
			Thisform.nDviCurs = Thisform.nCurs
			Thisform.txtDviCurs.Refresh()
		Endif
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE txtData.Valid
		This.Parent.dDataAct = This.Value
		This.Parent.actualizeaza_stare_valuta()
	ENDPROC

	PROCEDURE txtDiscBaza.Valid
		Thisform.nDiscBaza = This.Value
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE txtDviCurs.GotFocus
		Thisform.nOldVal = This.Value
	ENDPROC

	PROCEDURE txtDviCurs.Valid
		Thisform.nDviCurs = This.Value
		If This.Value <> Thisform.nOldVal
			Thisform.lDviCursDirty = .T.
		Endif
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE txtDviPartener.DblClick
		Thisform.cmddviPartener.Click()
	ENDPROC

	PROCEDURE txtDviPartener.GotFocus
		If This.Tag == 'SKIP'
			This.Tag = ''
			Return
		Endif
		If Thisform.optTipTva.Value = 2 And Empty(Nvl(Thisform.nDviIdPartener, 0))
			This.Tag = 'SKIP'
			Thisform.cmdDviPartener.Click()
		Endif
	ENDPROC

	PROCEDURE txtDviPartener.InteractiveChange
		Thisform.cmddviPartener.Click()
		This.Value = Thisform.cDviPartener
	ENDPROC

	PROCEDURE txtDviTvaVal.GotFocus
		Thisform.nOldVal = This.Value
	ENDPROC

	PROCEDURE txtDviTvaVal.Valid
		Thisform.nDviTvaVal = This.Value
		If This.Value <> Thisform.nOldVal
			Thisform.lDviTvaValDirty = .T.
		Endif
		Thisform.nDviTvaLei = Thisform.tva_dvi_lei()
	ENDPROC

	PROCEDURE txtDviValuta.DblClick
		Thisform.cmdDviValuta.Click()
	ENDPROC

	PROCEDURE txtExplicatieTva.DblClick
		Thisform.cmdExplicatieTva.Click()
	ENDPROC

	PROCEDURE txtExplicatieTva.InteractiveChange
		Thisform.cmdExplicatieTva.Click()
		this.Value = Thisform.cExplicatieTva
	ENDPROC

	PROCEDURE txtFelDoc.DblClick
		thisform.cmdfelDoc.Click()
	ENDPROC

	PROCEDURE txtFelDoc.GotFocus
		If This.Tag == 'SKIP'
			This.Tag = ''
			Return
		Endif
		If Empty(Nvl(Thisform.nIdFdoc, 0)) And Empty(Alltrim(Nvl(Thisform.cFelDoc, '')))
			This.Tag = 'SKIP'
			Thisform.cmdFelDoc.Click()
		Endif
	ENDPROC

	PROCEDURE txtFelDoc.InteractiveChange
		thisform.cmdfelDoc.Click()
		This.Value = Thisform.cFelDoc
		
	ENDPROC

	PROCEDURE txtFelDocDVI.DblClick
		thisform.cmdfelDocDVI.Click()
	ENDPROC

	PROCEDURE txtFelDocDVI.GotFocus
		If This.Tag == 'SKIP'
			This.Tag = ''
			Return
		Endif
		If Thisform.optTipTva.Value = 2 And Empty(Nvl(Thisform.nIdFdocDVI, 0)) And Empty(Alltrim(Nvl(Thisform.cFelDocDvi, '')))
			This.Tag = 'SKIP'
			Thisform.cmdFelDocDVI.Click()
		Endif
	ENDPROC

	PROCEDURE txtFelDocDVI.InteractiveChange
		Thisform.cmdFelDocDVI.Click()
		This.Value = Thisform.cFelDocDVI
	ENDPROC

	PROCEDURE txtPartener.DblClick
		Thisform.cmdPartener.Click()
	ENDPROC

	PROCEDURE txtPartener.GotFocus
		If This.Tag == 'SKIP'
			This.Tag = ''
			Return
		Endif
		If Empty(Nvl(Thisform.nIdPartener, 0))
			This.Tag = 'SKIP'
			Thisform.cmdPartener.Click()
		Endif
	ENDPROC

	PROCEDURE txtPartener.InteractiveChange
		Thisform.cmdPartener.Click()
		This.Value = Thisform.cPartener
	ENDPROC

	PROCEDURE txtProcentTva.Valid
		Thisform.nProcentTva = This.Value
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE txtSuma.Valid
		If This.Value <> Thisform.nSuma
			* suma s-a schimbat: reiau calculul automat al TVA-ului
			Thisform.lDviTvaValDirty = .F.
		Endif
		Thisform.nSuma = This.Value
		Thisform.recalc_tva()
	ENDPROC

	PROCEDURE txtValuta.DblClick
		Thisform.cmdvaluta.Click()
	ENDPROC

ENDDEFINE

DEFINE CLASS import_nota AS frm_termin_renunt OF "_frm_child.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Grid1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cNract.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cNract.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cPartC.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cPartC.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatie.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatie.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatieTva.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatieTva.Combo1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatieTva.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatia4.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatia4.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cScd.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cScd.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cScc.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cScc.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSuma.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSuma.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSumaVal.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSumaVal.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cInValuta.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cInValuta.Check1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatia5.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cExplicatia5.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cPartD.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cPartD.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cAscd.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cAscd.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cAscc.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cAscc.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cPtva.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cPtva.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cParticipaValuta.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cParticipaValuta.Check1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSerie_act.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSerie_act.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cDataAct.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cDataAct.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cFDoc.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cFDoc.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSe_scrie.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cSe_scrie._checkbox1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cTaxCode.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cTaxCode.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cTaxCode._combobox1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cValuta.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cValuta.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cCurs.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cCurs.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cTip.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Grid1.cTip.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Text2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Text3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtFtvaLei" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtFtvaVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Label1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Label3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblFtvaLei" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblFtvaVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cmd_executa1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_nou1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_sterge1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_copiaza1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_adauga_art" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_copie_art" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_sterge_art" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="chkSpargeSecundare" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cDenumire.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cDenumire.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCodMat.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCodMat.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCant.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCant.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cPretFactura.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cPretFactura.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cPretValutaCalculat.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cPretValutaCalculat.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cPretLeiCalculat.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cPretLeiCalculat.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cValoareValutaFactura.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cValoareValutaFactura.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cValoareValutaCalculat.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cValoareValutaCalculat.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cValoareLeiCalculat.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cValoareLeiCalculat.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCont.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCont.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cAcont.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cAcont.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cSerie.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cSerie.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cLot.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cLot.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cAdata_expirare.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cAdata_expirare.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.Column1.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.Column1.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCotaTva.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GridArt.cCotaTva.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_grdfooter1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblIncLei" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtIncLei" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblIncVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtIncVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDifLei" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtDifLei" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblDifVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtDifVal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_modiparam1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="tmrSync" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblSync" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lblLegenda" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: actualizeaza_banda
		*m: aliniaza_tva_la_baza
		*m: aplica_explicatie_tva
		*m: assign_analitic
		*m: calc_baze_cota_creditor
		*m: calc_doc_key
		*m: copiaza_valoare
		*m: creeaza_rand_s
		*m: disc_document
		*m: do_adauga_articol
		*m: do_adauga_factura
		*m: do_calculeaza_diferente
		*m: do_calculeaza_suma
		*m: do_copiaza_nota
		*m: do_executa_pret
		*m: do_modifica_explicatie_tva
		*m: do_modifica_fdoc
		*m: do_modiparam
		*m: do_sterge_articol
		*m: gaseste_jtva_cota
		*m: rand_protejat
		*m: recalculeaza
		*m: recalc_diferente
		*m: recalc_tva_document
		*m: refac_culori_documente
		*m: sincronizeaza
		*m: sparge_discount
		*m: sparge_document
		*m: sparge_tva_protejat
		*m: uneste_document
		*m: updateexplicatiesaft
		*m: valideaza_sume
		*p: cdvifeldoc		&& memoria DVI: textul felului de document al DVI (pt. redeschidere dialog)
		*p: cdvinr		&& memoria DVI: numarul DVI, ca sir
		*p: cdvipartener		&& memoria DVI: denumirea partenerului vamal
		*p: cdviserie		&& memoria DVI: seria DVI (de regula goala)
		*p: cmesajsync		&& mesajele valideaza_sume/sparge_document/recalc_diferente (banda de sincronizare)
		*p: coldval		&& valoarea celulei caracter la intrarea in focus (scc/ascc) - pereche cu noldval, numeric
		*p: ddvidata		&& memoria DVI: data DVI
		*p: ldialogaratat		&& dialogul "Adauga factura" a fost deschis automat la Activate (o singura data)
		*p: linsync		&& guard de reintrare in sincronizeaza()
		*p: lintern		&& Formularul este folosit pentru Import (.T.) sau pentru achizitii interne (.F.)
		*p: lrecalctva		&& recalculeaza automat T-urile nemanuale cand se modifica totalul facturii
		*p: lspargesecundare		&& spargerea facturilor secundare pe conturile/analiticele articolelor (implicit activa)
		*p: lsyncpending		&& sincronizare amanata, armata din Valid-uri, executata de tmrSync
		*p: nbazaprincipala_lei		&& baza principala lei (nr_doc minim B/S), numitor procente per rand (sincronizeaza)
		*p: nbazaprincipala_val		&& baza principala valuta, numitor procente per rand (sincronizeaza)
		*p: nbaza_lei		&& baza lei totala (recalculeaza) - documentele cu S insumeaza S, fara S insumeaza B
		*p: nbaza_val		&& baza valuta totala (recalculeaza)
		*p: ndif_lei		&& diferenta lei randul D (recalc_diferente)
		*p: ndif_val		&& diferenta valuta randul D (recalc_diferente)
		*p: ndisc_lei		&& discount lei totala (recalculeaza), suma randurilor G
		*p: ndisc_val		&& discount valuta totala (recalculeaza)
		*p: ndviidfdoc		&& memoria DVI: id_fdoc ales prima data prin caut_fdoc - cheia sesiunii DVI
		*p: ndviidpartener		&& memoria DVI: id_part al partenerului vamal
		*p: nid_part_finalizarenir
		*p: noldval		&& valoarea celulei la intrarea in focus (GotFocus) - Valid/LostFocus doar la modificare
		*p: ntva_lei		&& TVA lei totala (recalculeaza)
		*p: ntva_val		&& TVA valuta totala (recalculeaza)
		*p: oact
		*p: procent_lei		&& procent incarcare lei (100 + transport/taxe), calculat in recalculeaza()
		*p: procent_val		&& procent incarcare valuta, calculat in recalculeaza()
		*p: tprocente
		*p: tsuma
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 3
		cdvifeldoc = ""
		cdvinr = ""
		cdvipartener = ""
		cdviserie = ""
		cmesajsync = ""
		coldval = ""
		ddvidata = {}
		DoCreate = .T.
		Height = 620
		KeyPreview = .T.
		ldialogaratat = .F.
		linsync = .F.
		lintern = .F.
		lrecalctva = .T.
		lspargesecundare = .T.
		lsyncpending = .F.
		Name = "import_nota"
		nbazaprincipala_lei = 0
		nbazaprincipala_val = 0
		nbaza_lei = 0
		nbaza_val = 0
		ndif_lei = 0
		ndif_val = 0
		ndisc_lei = 0
		ndisc_val = 0
		ndviidfdoc = 0
		ndviidpartener = 0
		nid_part_finalizarenir = 
		noldval = 0
		ntva_lei = 0
		ntva_val = 0
		oact = 
		procent_lei = 0
		procent_val = 0
		tprocente = 0
		tsuma = 0
		Width = 1000
		_memberdata = <VFPData>
			<memberdata name="updateexplicatiesaft" display="UpdateExplicatieSAFT"/>
		</VFPData>
		_shape1.Anchor = 10
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 1001
		_shape2.Anchor = 8
		_shape2.Left = 937
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 60
		Lb_titlu_alb_b121.Caption = "ACHIZIÞIE DIN IMPORT MARFÃ/MATERIALE"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		BUT_TERMIN1.Anchor = 8
		BUT_TERMIN1.Left = 968
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.Top = 1
		Gridsort1.Name = "Gridsort1"
		But_renunt1.Anchor = 8
		But_renunt1.Left = 939
		But_renunt1.Name = "But_renunt1"
		But_renunt1.Top = 1
	*</PropValue>

	ADD OBJECT '_grdfooter1' AS _grdfooter WITH ;
		Anchor = 14, ;
		ccolwithlabel = cDenumire, ;
		csourcegrid = , ;
		csumcolumns = cValoareValutaFactura, cValoareValutaCalculat, cValoareLeiCalculat, ;
		ctotallabelexpression = 'TOTAL', ;
		Left = 4, ;
		Name = "_grdfooter1", ;
		Top = 573, ;
		Width = 990
		*< END OBJECT: ClassLib="_grd_base.vcx" BaseClass="grid" />

	ADD OBJECT 'But_adauga_art' AS but_nou WITH ;
		Anchor = 9, ;
		caction = do_adauga_articol, ;
		Left = 770, ;
		Name = "But_adauga_art", ;
		ToolTipText = "Adauga repere", ;
		Top = 376
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_copiaza1' AS but_copiaza WITH ;
		Anchor = 8, ;
		caction = do_copiaza_nota, ;
		Left = 843, ;
		Name = "But_copiaza1", ;
		ToolTipText = "Copiaza factura (Da=document, Nu=linie)", ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_copie_art' AS but_copiaza WITH ;
		Anchor = 9, ;
		caction = do_copie, ;
		Left = 802, ;
		Name = "But_copie_art", ;
		ToolTipText = "Copiaza reperul curent", ;
		Top = 376
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_modiparam1' AS but_modiparam WITH ;
		Anchor = 8, ;
		Left = 779, ;
		Name = "But_modiparam1", ;
		ToolTipText = "Import fisier XLS", ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_nou1' AS but_nou WITH ;
		Anchor = 8, ;
		Left = 811, ;
		Name = "But_nou1", ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_sterge1' AS but_sterge WITH ;
		Anchor = 8, ;
		Left = 875, ;
		Name = "But_sterge1", ;
		ToolTipText = "Stergere linia sau nota curenta", ;
		Top = 1, ;
		Visible = .T.
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_sterge_art' AS but_sterge WITH ;
		Anchor = 9, ;
		caction = do_sterge_articol, ;
		Left = 834, ;
		Name = "But_sterge_art", ;
		ToolTipText = "Sterge articolul curent", ;
		Top = 376, ;
		Visible = .T.
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'chkSpargeSecundare' AS _checkbox WITH ;
		Alignment = 0, ;
		Anchor = 9, ;
		Caption = "Sincronizeaza facturile secundare", ;
		ControlSource = "Thisform.lSpargeSecundare", ;
		Height = 18, ;
		Left = 764, ;
		Name = "chkSpargeSecundare", ;
		Top = 406, ;
		Width = 214
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'Cmd_executa1' AS cmd_executa WITH ;
		Anchor = 9, ;
		Caption = "\<Recalculeaza", ;
		FontBold = .T., ;
		Height = 27, ;
		Left = 870, ;
		Name = "Cmd_executa1", ;
		Top = 376, ;
		Width = 124
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Grid1' AS grid WITH ;
		Anchor = 11, ;
		BackColor = 255,255,255, ;
		ColumnCount = 24, ;
		DeleteMark = .F., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		HeaderHeight = 49, ;
		Height = 288, ;
		Left = 4, ;
		Name = "Grid1", ;
		Panel = 1, ;
		RecordSource = "introdc", ;
		RecordSourceType = 1, ;
		RowHeight = 19, ;
		TabIndex = 2, ;
		Top = 60, ;
		Width = 990, ;
		ZOrderSet = 5, ;
		Column1.BackColor = 255,255,255, ;
		Column1.ColumnOrder = 5, ;
		Column1.ControlSource = "nract", ;
		Column1.FontName = "Arial", ;
		Column1.FontSize = 10, ;
		Column1.Name = "cNract", ;
		Column1.Visible = .T., ;
		Column1.Width = 71, ;
		Column2.BackColor = 255,255,255, ;
		Column2.ColumnOrder = 6, ;
		Column2.ControlSource = "partc", ;
		Column2.CurrentControl = "Text1", ;
		Column2.FontName = "Arial", ;
		Column2.FontSize = 10, ;
		Column2.Name = "cPartC", ;
		Column2.Sparse = .T., ;
		Column2.Visible = .T., ;
		Column2.Width = 109, ;
		Column3.BackColor = 255,255,255, ;
		Column3.ColumnOrder = 7, ;
		Column3.ControlSource = "explicatia", ;
		Column3.FontName = "Arial", ;
		Column3.FontSize = 10, ;
		Column3.Name = "cExplicatie", ;
		Column3.Visible = .T., ;
		Column3.Width = 92, ;
		Column4.BackColor = 255,255,255, ;
		Column4.ColumnOrder = 9, ;
		Column4.ControlSource = "explicatie_tva", ;
		Column4.CurrentControl = "Text1", ;
		Column4.FontName = "Arial", ;
		Column4.FontSize = 10, ;
		Column4.Name = "cExplicatieTva", ;
		Column4.ReadOnly = .F., ;
		Column4.Sparse = .F., ;
		Column4.Width = 134, ;
		Column5.BackColor = 255,255,255, ;
		Column5.ColumnOrder = 22, ;
		Column5.ControlSource = "explicatia4", ;
		Column5.FontName = "Arial", ;
		Column5.FontSize = 10, ;
		Column5.Name = "cExplicatia4", ;
		Column5.Visible = .T., ;
		Column5.Width = 46, ;
		Column6.BackColor = 255,255,255, ;
		Column6.ColumnOrder = 10, ;
		Column6.ControlSource = "scd", ;
		Column6.FontName = "Arial", ;
		Column6.FontSize = 10, ;
		Column6.Name = "cScd", ;
		Column6.Visible = .T., ;
		Column6.Width = 46, ;
		Column7.BackColor = 255,255,255, ;
		Column7.ColumnOrder = 12, ;
		Column7.ControlSource = "scc", ;
		Column7.FontName = "Arial", ;
		Column7.FontSize = 10, ;
		Column7.Name = "cScc", ;
		Column7.Visible = .T., ;
		Column7.Width = 41, ;
		Column8.Alignment = 1, ;
		Column8.BackColor = 255,255,255, ;
		Column8.ColumnOrder = 15, ;
		Column8.ControlSource = "suma", ;
		Column8.FontName = "Arial", ;
		Column8.FontSize = 10, ;
		Column8.Format = "R", ;
		Column8.InputMask = (get_mask(12,gnPc)), ;
		Column8.Name = "cSuma", ;
		Column8.Visible = .T., ;
		Column8.Width = 75, ;
		Column9.BackColor = 255,255,255, ;
		Column9.ColumnOrder = 16, ;
		Column9.ControlSource = "suma_val", ;
		Column9.FontName = "Arial", ;
		Column9.FontSize = 10, ;
		Column9.InputMask = (get_mask(12,gnPval)), ;
		Column9.Name = "cSumaVal", ;
		Column9.Width = 76, ;
		Column10.BackColor = 255,255,255, ;
		Column10.ColumnOrder = 19, ;
		Column10.ControlSource = "in_valuta", ;
		Column10.FontName = "Arial", ;
		Column10.FontSize = 10, ;
		Column10.Name = "cInValuta", ;
		Column10.Sparse = .F., ;
		Column10.Width = 84, ;
		Column11.BackColor = 255,255,255, ;
		Column11.ColumnOrder = 23, ;
		Column11.ControlSource = "explicatia5", ;
		Column11.FontName = "Arial", ;
		Column11.FontSize = 10, ;
		Column11.Name = "cExplicatia5", ;
		Column11.Visible = .T., ;
		Column11.Width = 45, ;
		Column12.BackColor = 255,255,255, ;
		Column12.ColumnOrder = 21, ;
		Column12.ControlSource = "PARTD", ;
		Column12.FontName = "Arial", ;
		Column12.FontSize = 10, ;
		Column12.Name = "cPartD", ;
		Column12.Visible = .T., ;
		Column12.Width = 91, ;
		Column13.BackColor = 255,255,255, ;
		Column13.ColumnOrder = 11, ;
		Column13.ControlSource = "ascd", ;
		Column13.FontName = "Arial", ;
		Column13.FontSize = 10, ;
		Column13.Name = "cAscd", ;
		Column13.Width = 40, ;
		Column14.BackColor = 255,255,255, ;
		Column14.ColumnOrder = 13, ;
		Column14.ControlSource = "ascc", ;
		Column14.FontName = "Arial", ;
		Column14.FontSize = 10, ;
		Column14.Name = "cAscc", ;
		Column14.Width = 44, ;
		Column15.BackColor = 255,255,255, ;
		Column15.ColumnOrder = 8, ;
		Column15.ControlSource = "ptva", ;
		Column15.FontName = "Arial", ;
		Column15.FontSize = 10, ;
		Column15.InputMask = "999", ;
		Column15.Name = "cPtva", ;
		Column15.Width = 41, ;
		Column16.BackColor = 255,255,255, ;
		Column16.ColumnOrder = 20, ;
		Column16.ControlSource = "participa_valuta", ;
		Column16.CurrentControl = "Check1", ;
		Column16.FontName = "Arial", ;
		Column16.FontSize = 10, ;
		Column16.Name = "cParticipaValuta", ;
		Column16.Sparse = .F., ;
		Column16.Width = 76, ;
		Column17.BackColor = 255,255,255, ;
		Column17.ColumnOrder = 4, ;
		Column17.ControlSource = "serie_act", ;
		Column17.FontName = "Arial", ;
		Column17.FontSize = 10, ;
		Column17.Name = "cSerie_act", ;
		Column17.Width = 70, ;
		Column18.BackColor = 255,255,255, ;
		Column18.ColumnOrder = 2, ;
		Column18.ControlSource = "dataact", ;
		Column18.FontName = "Arial", ;
		Column18.FontSize = 10, ;
		Column18.Name = "cDataAct", ;
		Column19.BackColor = 255,255,255, ;
		Column19.ColumnOrder = 3, ;
		Column19.ControlSource = "fdoc", ;
		Column19.FontName = "Arial", ;
		Column19.FontSize = 10, ;
		Column19.Name = "cFDoc", ;
		Column19.ReadOnly = .F., ;
		Column20.BackColor = 255,255,255, ;
		Column20.ColumnOrder = 24, ;
		Column20.ControlSource = "se_scrie", ;
		Column20.FontName = "Arial", ;
		Column20.FontSize = 10, ;
		Column20.Name = "cSe_scrie", ;
		Column20.Sparse = .F., ;
		Column20.Visible = .T., ;
		Column20.Width = 87, ;
		Column21.BackColor = 255,255,255, ;
		Column21.Bound = .F., ;
		Column21.ColumnOrder = 14, ;
		Column21.ControlSource = "Iif(Seek(introdc.taxcode,'saft_taxtable','taxcode'),saft_taxtable.taxname,'')", ;
		Column21.CurrentControl = "_combobox1", ;
		Column21.FontName = "Arial", ;
		Column21.FontSize = 10, ;
		Column21.Name = "cTaxCode", ;
		Column21.Sparse = .F., ;
		Column21.Width = 176, ;
		Column22.BackColor = 255,255,255, ;
		Column22.ColumnOrder = 17, ;
		Column22.ControlSource = "nume_val", ;
		Column22.FontName = "Arial", ;
		Column22.FontSize = 10, ;
		Column22.Name = "cValuta", ;
		Column22.ReadOnly = .F., ;
		Column22.Visible = .T., ;
		Column22.Width = 55, ;
		Column23.Alignment = 1, ;
		Column23.BackColor = 255,255,255, ;
		Column23.ColumnOrder = 18, ;
		Column23.ControlSource = "curs", ;
		Column23.FontName = "Arial", ;
		Column23.FontSize = 10, ;
		Column23.InputMask = (get_mask(12,gnPCurs)), ;
		Column23.Name = "cCurs", ;
		Column23.ReadOnly = .F., ;
		Column23.Visible = .T., ;
		Column23.Width = 70, ;
		Column24.BackColor = 255,255,255, ;
		Column24.Bound = .F., ;
		Column24.ColumnOrder = 1, ;
		Column24.ControlSource = "introdc.tip_rand + Iif(introdc.mod_manual=1,'*',' ')", ;
		Column24.FontName = "Arial", ;
		Column24.FontSize = 10, ;
		Column24.Name = "cTip", ;
		Column24.ReadOnly = .T., ;
		Column24.Width = 32
		*< END OBJECT: BaseClass="grid" />

	ADD OBJECT 'Grid1.cAscc.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "ASCC", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cAscc.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cAscd.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "ASCD", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cAscd.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cCurs.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Curs", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cCurs.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cDataAct.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Data doc.", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cDataAct.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cExplicatia4.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Procent lei", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1", ;
		WordWrap = .T.
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cExplicatia4.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		Visible = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cExplicatia5.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Procent valuta", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1", ;
		WordWrap = .T.
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cExplicatia5.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cExplicatie.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Explicatia", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cExplicatie.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		Visible = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cExplicatieTva.Combo1' AS combobox WITH ;
		BoundColumn = 1, ;
		BoundTo = .T., ;
		ColumnCount = 1, ;
		ColumnLines = .F., ;
		ColumnWidths = "250,0,0", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Height = 10, ;
		Left = 17, ;
		Name = "Combo1", ;
		RowSource = "jtva_coloane2.denumire,cota_tva,id_jtva_coloana", ;
		RowSourceType = 2, ;
		SpecialEffect = 1, ;
		Style = 2, ;
		Top = 23, ;
		Visible = .T., ;
		Width = 10
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'Grid1.cExplicatieTva.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Explicatie TVA", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cExplicatieTva.Text1' AS textbox WITH ;
		BorderStyle = 0, ;
		Height = 23, ;
		Left = 104, ;
		Name = "Text1", ;
		ReadOnly = .F., ;
		Top = 87, ;
		Width = 100
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cFDoc.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Fel doc.", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cFDoc.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .F.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cInValuta.Check1' AS checkbox WITH ;
		Alignment = 2, ;
		Caption = "", ;
		Centered = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Height = 17, ;
		Left = 49, ;
		Name = "Check1", ;
		TabStop = .F., ;
		Top = 83, ;
		Width = 60
		*< END OBJECT: BaseClass="checkbox" />

	ADD OBJECT 'Grid1.cInValuta.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Valuta in contabilitate", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1", ;
		WordWrap = .T.
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cNract.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Nr factura", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cNract.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		Visible = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cPartC.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Partener credit", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cPartC.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		Visible = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cPartD.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Partener debit", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cPartD.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cParticipaValuta.Check1' AS checkbox WITH ;
		Alignment = 2, ;
		Caption = "", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Height = 17, ;
		Left = 21, ;
		Name = "Check1", ;
		Top = 71, ;
		Width = 60
		*< END OBJECT: BaseClass="checkbox" />

	ADD OBJECT 'Grid1.cParticipaValuta.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Participa la pret", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1", ;
		WordWrap = .T.
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cPtva.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "TVA %", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cPtva.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cScc.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "SCC", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cScc.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		Visible = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cScd.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "SCD", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cScd.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		Visible = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cSe_scrie._checkbox1' AS _checkbox WITH ;
		Alignment = 2, ;
		AutoSize = .F., ;
		Caption = "", ;
		Centered = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Left = 41, ;
		Name = "_checkbox1", ;
		Top = 47
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'Grid1.cSe_scrie.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Se scrie nota chiar daca suma este 0", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1", ;
		WordWrap = .T.
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cSerie_act.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Serie factura", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1", ;
		WordWrap = .T.
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cSerie_act.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Format = "!", ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cSuma.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Suma", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cSuma.Text1' AS textbox WITH ;
		Alignment = 1, ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		Visible = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cSumaVal.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Suma valuta", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cSumaVal.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cTaxCode._combobox1' AS _combobox WITH ;
		BorderStyle = 0, ;
		BoundColumn = 3, ;
		BoundTo = .T., ;
		ColumnCount = 2, ;
		ColumnLines = .F., ;
		ColumnWidths = "450,100", ;
		ControlSource = "introdc.taxcode", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Left = 84, ;
		Name = "_combobox1", ;
		RowSource = "select taxname, procent_taxa, taxcode from saft_taxtable where tva_achizitii=1 into cursor crsTaxTableX", ;
		RowSourceType = 3, ;
		Top = 87
		*< END OBJECT: ClassLib="..\..\..\roacont\comun\clase\_baza.vcx" BaseClass="combobox" />

	ADD OBJECT 'Grid1.cTaxCode.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Taxa SAFT", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cTaxCode.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cTip.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Tip", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cTip.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Grid1.cValuta.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Valuta", ;
		FontBold = .T., ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'Grid1.cValuta.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt' AS grid WITH ;
		Anchor = 15, ;
		ColumnCount = 16, ;
		DeleteMark = .F., ;
		FontSize = 10, ;
		Height = 145, ;
		Left = 4, ;
		Name = "GridArt", ;
		Panel = 1, ;
		RecordSource = "rul_temp", ;
		RowHeight = 19, ;
		TabIndex = 14, ;
		Top = 428, ;
		Width = 990, ;
		Column1.ControlSource = "denumire", ;
		Column1.FontName = "Arial", ;
		Column1.FontSize = 10, ;
		Column1.Name = "cDenumire", ;
		Column1.ReadOnly = .T., ;
		Column1.Width = 181, ;
		Column2.ControlSource = "codmat", ;
		Column2.FontName = "Arial", ;
		Column2.FontSize = 10, ;
		Column2.Name = "cCodMat", ;
		Column2.ReadOnly = .T., ;
		Column2.Width = 84, ;
		Column3.BackColor = 240,248,255, ;
		Column3.ColumnOrder = 6, ;
		Column3.ControlSource = "cant", ;
		Column3.FontName = "Arial", ;
		Column3.FontSize = 10, ;
		Column3.InputMask = (get_mask(10,gnPcant)), ;
		Column3.Name = "cCant", ;
		Column3.Width = 67, ;
		Column4.BackColor = 230,242,255, ;
		Column4.ColumnOrder = 7, ;
		Column4.ControlSource = "pret_val", ;
		Column4.FontName = "Arial", ;
		Column4.FontSize = 10, ;
		Column4.InputMask = (get_mask(10,gnPpretval)), ;
		Column4.Name = "cPretFactura", ;
		Column4.Width = 108, ;
		Column5.BackColor = 240,248,255, ;
		Column5.ColumnOrder = 8, ;
		Column5.ControlSource = "pretd", ;
		Column5.FontName = "Arial", ;
		Column5.FontSize = 10, ;
		Column5.InputMask = (get_mask(10,gnPPretval)), ;
		Column5.Name = "cPretValutaCalculat", ;
		Column5.Width = 114, ;
		Column6.BackColor = 230,242,255, ;
		Column6.ColumnOrder = 9, ;
		Column6.ControlSource = "pret", ;
		Column6.FontName = "Arial", ;
		Column6.FontSize = 10, ;
		Column6.InputMask = (get_mask(10,gnPpret)), ;
		Column6.Name = "cPretLeiCalculat", ;
		Column6.Width = 100, ;
		Column7.Bound = .F., ;
		Column7.ColumnOrder = 11, ;
		Column7.ControlSource = "round(pret_val*cant, gnPval)", ;
		Column7.FontName = "Arial", ;
		Column7.FontSize = 10, ;
		Column7.InputMask = (get_mask(16,gnPval)), ;
		Column7.Name = "cValoareValutaFactura", ;
		Column7.Width = 128, ;
		Column8.Bound = .F., ;
		Column8.ColumnOrder = 12, ;
		Column8.ControlSource = "round(pretd*cant, gnPval)", ;
		Column8.FontName = "Arial", ;
		Column8.FontSize = 10, ;
		Column8.InputMask = (get_mask(16,gnPval)), ;
		Column8.Name = "cValoareValutaCalculat", ;
		Column8.Width = 130, ;
		Column9.Bound = .F., ;
		Column9.ColumnOrder = 13, ;
		Column9.ControlSource = "round(pret*cant, gnPc)", ;
		Column9.FontName = "Arial", ;
		Column9.FontSize = 10, ;
		Column9.InputMask = (get_mask(10,gnPc)), ;
		Column9.Name = "cValoareLeiCalculat", ;
		Column9.Width = 110, ;
		Column10.BackColor = 240,248,255, ;
		Column10.ColumnOrder = 4, ;
		Column10.ControlSource = "cont", ;
		Column10.FontName = "Arial", ;
		Column10.FontSize = 10, ;
		Column10.Name = "cCont", ;
		Column10.ReadOnly = .F., ;
		Column10.Width = 43, ;
		Column11.BackColor = 240,248,255, ;
		Column11.ColumnOrder = 5, ;
		Column11.ControlSource = "acont", ;
		Column11.FontName = "Arial", ;
		Column11.FontSize = 10, ;
		Column11.Name = "cAcont", ;
		Column11.ReadOnly = .F., ;
		Column11.Width = 47, ;
		Column12.BackColor = 240,248,255, ;
		Column12.ColumnOrder = 3, ;
		Column12.ControlSource = "serie", ;
		Column12.FontName = "Arial", ;
		Column12.FontSize = 10, ;
		Column12.Format = "!K", ;
		Column12.Name = "cSerie", ;
		Column12.Width = 123, ;
		Column13.BackColor = 240,248,255, ;
		Column13.ColumnOrder = 14, ;
		Column13.ControlSource = "lot", ;
		Column13.FontName = "Arial", ;
		Column13.FontSize = 10, ;
		Column13.Name = "cLot", ;
		Column14.BackColor = 240,248,255, ;
		Column14.ColumnOrder = 15, ;
		Column14.ControlSource = "adata_expirare", ;
		Column14.FontName = "Arial", ;
		Column14.FontSize = 10, ;
		Column14.Name = "cAdata_expirare", ;
		Column14.Width = 79, ;
		Column15.BackColor = 240,248,255, ;
		Column15.ColumnOrder = 10, ;
		Column15.ControlSource = "proc_disc", ;
		Column15.FontName = "Arial", ;
		Column15.FontSize = 10, ;
		Column15.InputMask = (get_mask(3,2)), ;
		Column15.Name = "Column1", ;
		Column15.Width = 50, ;
		Column16.BackColor = 240,248,255, ;
		Column16.ColumnOrder = 16, ;
		Column16.ControlSource = "cota_tva", ;
		Column16.FontName = "Arial", ;
		Column16.FontSize = 10, ;
		Column16.InputMask = (get_mask(3,2)), ;
		Column16.Name = "cCotaTva", ;
		Column16.Width = 60
		*< END OBJECT: BaseClass="grid" />

	ADD OBJECT 'GridArt.cAcont.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Analitic", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cAcont.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .F.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cAdata_expirare.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Data expirare", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cAdata_expirare.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cCant.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Cantitate", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cCant.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cCodMat.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Cod material", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cCodMat.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cCont.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Cont", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cCont.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .F.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cCotaTva.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Cota TVA", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cCotaTva.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cDenumire.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Denumire", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cDenumire.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cLot.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Lot", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cLot.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.Column1.Header1' AS header WITH ;
		Caption = "Disc. %", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.Column1.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cPretFactura.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Pret valuta factura", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cPretFactura.Text1' AS textbox WITH ;
		BackColor = 230,242,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cPretLeiCalculat.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Pret lei calculat", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cPretLeiCalculat.Text1' AS textbox WITH ;
		BackColor = 230,242,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cPretValutaCalculat.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Pret valuta calculat", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cPretValutaCalculat.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cSerie.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Serie", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cSerie.Text1' AS textbox WITH ;
		BackColor = 240,248,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cValoareLeiCalculat.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Valoare lei calculat", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cValoareLeiCalculat.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cValoareValutaCalculat.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Valoare valuta calculat", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cValoareValutaCalculat.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'GridArt.cValoareValutaFactura.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Valoare valuta factura", ;
		FontName = "Arial", ;
		FontSize = 10, ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GridArt.cValoareValutaFactura.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		FontName = "Arial", ;
		FontSize = 10, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'Label1' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Suma", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 8, ;
		Name = "Label1", ;
		TabIndex = 13, ;
		Top = 353, ;
		Width = 39, ;
		ZOrderSet = 9
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'Label3' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Suma val.", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 130, ;
		Name = "Label3", ;
		TabIndex = 13, ;
		Top = 353, ;
		Width = 66, ;
		ZOrderSet = 9
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDifLei' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Dif. lei", ;
		FontBold = .F., ;
		Height = 18, ;
		Left = 795, ;
		Name = "lblDifLei", ;
		Top = 353, ;
		Width = 38
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblDifVal' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Dif. val.", ;
		FontBold = .F., ;
		Height = 18, ;
		Left = 895, ;
		Name = "lblDifVal", ;
		Top = 353, ;
		Width = 44
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'LblFtvaLei' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "F.TVA", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 278, ;
		Name = "LblFtvaLei", ;
		TabIndex = 13, ;
		Top = 353, ;
		Width = 40, ;
		ZOrderSet = 9
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'LblFtvaVal' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "F.TVA val.", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 403, ;
		Name = "LblFtvaVal", ;
		TabIndex = 13, ;
		Top = 353, ;
		Width = 67, ;
		ZOrderSet = 9
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblIncLei' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Inc. lei %", ;
		FontBold = .F., ;
		Height = 18, ;
		Left = 554, ;
		Name = "lblIncLei", ;
		Top = 353, ;
		Width = 56
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblIncVal' AS _label WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "Inc. val. %", ;
		FontBold = .F., ;
		Height = 18, ;
		Left = 673, ;
		Name = "lblIncVal", ;
		Top = 353, ;
		Width = 62
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT 'lblLegenda' AS label WITH ;
		Anchor = 11, ;
		Caption = "Tip rand: B=factura (nesincronizata)   S=sincronizat pe cont   T=TVA   D=DIFERENTE   *=modificat manual", ;
		FontItalic = .T., ;
		Height = 16, ;
		Left = 4, ;
		Name = "lblLegenda", ;
		Top = 398, ;
		Width = 756
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'lblSync' AS label WITH ;
		Anchor = 11, ;
		BackColor = 226,239,218, ;
		BackStyle = 1, ;
		Caption = "Sincronizat", ;
		FontBold = .T., ;
		Height = 20, ;
		Left = 4, ;
		Name = "lblSync", ;
		Top = 376, ;
		Width = 756
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'Text2' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = (get_mask(12,gnPc)), ;
		Left = 49, ;
		Name = "Text2", ;
		TabIndex = 12, ;
		Top = 350, ;
		Value = 0, ;
		Width = 76, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'Text3' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = (get_mask(12,gnPVAL)), ;
		Left = 197, ;
		Name = "Text3", ;
		TabIndex = 12, ;
		Top = 350, ;
		Value = 0, ;
		Width = 76, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'tmrSync' AS timer WITH ;
		Enabled = .T., ;
		Height = 23, ;
		Interval = 0, ;
		Left = -25, ;
		Name = "tmrSync", ;
		Top = 0, ;
		Width = 23
		*< END OBJECT: BaseClass="timer" />

	ADD OBJECT 'TxtDifLei' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "thisform.ndif_lei", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = (get_mask(10,gnPc)), ;
		Left = 838, ;
		Name = "TxtDifLei", ;
		Top = 350, ;
		Width = 52
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'TxtDifVal' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "thisform.ndif_val", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = (get_mask(10,gnPval)), ;
		Left = 946, ;
		Name = "TxtDifVal", ;
		Top = 350, ;
		Width = 52
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'TxtFtvaLei' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = (get_mask(12,gnPc)), ;
		Left = 322, ;
		Name = "TxtFtvaLei", ;
		TabIndex = 12, ;
		Top = 350, ;
		Value = 0, ;
		Width = 76, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'TxtFtvaVal' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = (get_mask(12,gnPVAL)), ;
		Left = 473, ;
		Name = "TxtFtvaVal", ;
		TabIndex = 12, ;
		Top = 350, ;
		Value = 0, ;
		Width = 76, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'TxtIncLei' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "thisform.procent_lei", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = "999.99", ;
		Left = 616, ;
		Name = "TxtIncLei", ;
		Top = 350, ;
		Width = 52
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'TxtIncVal' AS _textbox WITH ;
		Alignment = 1, ;
		Anchor = 3, ;
		BackStyle = 0, ;
		ControlSource = "thisform.procent_val", ;
		DisabledForeColor = 0,64,128, ;
		Enabled = .F., ;
		FontBold = .F., ;
		ForeColor = 0,64,128, ;
		Format = "r", ;
		Height = 23, ;
		InputMask = "999.99", ;
		Left = 738, ;
		Name = "TxtIncVal", ;
		Top = 350, ;
		Width = 52
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="textbox" />
	
	PROCEDURE Activate
		*!* Deschid automat dialogul "Adauga factura" la prima activare (numai pe modul
		*!* import), dupa ce formularul e deja vizibil in spatele dialogului.
		DoDefault()
		If !This.lIntern And !This.lDialogAratat
			This.lDialogAratat = .T.
			This.do_adauga()
		Endif
	ENDPROC

	PROCEDURE actualizeaza_banda
		*!* Banda de stare (sincronizat / nesincronizat, incarcarea pretului) si totalurile formularului.
		If Empty(This.cmesajsync)
			This.lblSync.BackColor = Rgb(226,239,218)
			This.lblSync.Caption = 'Sincronizat   |   Incarcare pret (transport/taxe): +' + Alltrim(Str(This.procent_val * This.procent_lei / 100 - 100, 12, 4)) + ' %'
		Else
			This.lblSync.BackColor = Rgb(255,221,221)
			This.lblSync.Caption = Left('NESINCRONIZAT: ' + Strtran(Strtran(This.cmesajsync, Chr(13), ''), Chr(10), ' | '), 254)
		Endif
		This.text2.Value = This.nbaza_lei + This.ntva_lei - This.ndisc_lei
		This.text3.Value = This.nbaza_val + This.ntva_val - This.ndisc_val
		This.txtftvalei.Value = This.nbaza_lei
		This.TxtIncLei.Refresh()
		If !This.lIntern
			This.txtftvaval.Value = This.nbaza_val
			This.TxtIncVal.Refresh()
			This.TxtDifVal.Refresh()
		Endif
		This.TxtDifLei.Refresh()
		If Vartype(This._grdfooter1) = 'O'
			This._grdfooter1.calcTotal()
		Endif
	ENDPROC

	PROCEDURE aliniaza_tva_la_baza
		*!* Aliniaza randurile T ale documentului la familia de explicatii a randului S de aceeasi
		*!* cota (perechea de TVA din nomenclator), reface taxcode (SAFT) si comutarea scc
		*!* 4427/creditor S; randurile cu explicatia aleasa manual (expl_manual=1) raman neatinse.
		Lparameters tcDocKey
		Local lcSel, lnCotaCrt, lnIdJtvaT
		lcSel = Select()
		
		Select Distinct introdc.ptva As cota, jb.id_tva As id_jtva_t, jt.denumire As denumire, ;
			introdc.scc As scc_s, introdc.ascc As ascc_s ;
			From introdc, jtva_coloane2 jb, jtva_coloane2 jt ;
			Where introdc.doc_key == tcDocKey And introdc.tip_rand == 'S' And Nvl(introdc.ptva,0) > 0 ;
			And jb.id_jtva_coloana = introdc.id_jtva_coloana And Nvl(jb.cota_tva,0) = Nvl(introdc.ptva,0) ;
			And Nvl(jb.id_tva,0) > 0 And jt.id_jtva_coloana = jb.id_tva ;
			Into Cursor crsPerecheT NOFILTER
		
		Select introdc
		Scan For doc_key == tcDocKey And tip_rand == 'T' And Nvl(expl_manual,0) <> 1 And Nvl(ptva,0) > 0
			lnCotaCrt = ptva
			Select crsPerecheT
			Locate For cota = lnCotaCrt
			lnIdJtvaT = Iif(Found(), crsPerecheT.id_jtva_t, 0)
			Select introdc
			If lnIdJtvaT <> 0 And lnIdJtvaT <> Nvl(id_jtva_coloana,0)
				Replace id_jtva_coloana With lnIdJtvaT, explicatie_tva With crsPerecheT.denumire
				If Seek(lnIdJtvaT, "cJtvaCol4427", "id_jtva")
					Replace scc With '4427', ascc With ''
				Else
					*!* creditorul propriu al randului T (spargerea pe creditori) se pastreaza - se reface doar iesirea din 4427
					If Alltrim(Nvl(scc,'')) == '4427'
						Replace scc With crsPerecheT.scc_s, ascc With Nvl(crsPerecheT.ascc_s,'')
					Endif
				Endif
				Thisform.UpdateExplicatieSAFT()
			Endif
		Endscan
		Use In crsPerecheT
		
		Select (lcSel)
	ENDPROC

	PROCEDURE aplica_explicatie_tva
		*!* Aplica explicatia TVA pe randul curent si pe randurile T de aceeasi cota ale documentului
		*!* (comutare scc 4426=4427 / creditorul bazei + UpdateExplicatieSAFT). Se apeleaza cu randul
		*!* curent pozitionat pe un rand non-T (B sau S); pozitia initiala se restaureaza la iesire.
		Lparameters tnIdJtvaColoana
		Local lnPtva, lcExplicatieTva, lnId_tva, lnId_jtva_coloanaTVA, lnCota_tva, lcExplicatie_TVA
		Local lcDocKey, lcTipRand, lcScd, lnTaxCodeBaza, lcSccS, lcAsccS, lnRanduriT
		
		Select jtva_coloane2
		Locate For id_jtva_coloana = tnIdJtvaColoana
		If !Found()
			Return .F.
		Endif
		lnPtva          = jtva_coloane2.cota_Tva
		lcExplicatieTva = jtva_coloane2.denumire
		lnId_tva        = jtva_coloane2.id_Tva
		
		Select introdc
		lcDocKey = Padr(Thisform.calc_doc_key(), Len(doc_key))
		lcTipRand = tip_rand
		lcScd = scd
		lcSccS = Nvl(scc,'')
		lcAsccS = Nvl(ascc,'')
		Replace id_jtva_coloana With tnIdJtvaColoana, ptva With lnPtva, explicatie_tva With lcExplicatieTva
		If lcTipRand == 'T'
			*!* explicatie aleasa direct pe randul de TVA - sincronizarea nu o realiniaza la familia bazei
			Replace expl_manual With 1
		Endif
		If lcTipRand == 'G'
			*!* randul de discount se editeaza local, fara sa atinga randul de TVA al documentului
			Thisform.UpdateExplicatieSAFT()
			Replace cu_tva With Iif(lnPtva = 0, 0, 1)
			Return .T.
		Endif
		
		If lcTipRand <> 'T'
			Thisform.UpdateExplicatieSAFT()
			lnTaxCodeBaza = taxcode
			If lnPtva = 0
				Select introdc
				Replace cu_tva With 0
				Locate For doc_key == lcDocKey And tip_rand = 'T'
				If Found()
					Replace id_jtva_coloana With 0, ptva With 0, explicatie_tva With '', cu_tva With 0
				Endif
			Else && randul de TVA al documentului
				Select jtva_coloane2
				Locate For id_jtva_coloana = lnId_tva
				If Found()
					lnId_jtva_coloanaTVA = jtva_coloane2.id_jtva_coloana
					lnCota_tva           = jtva_coloane2.cota_Tva
					lcExplicatie_TVA     = jtva_coloane2.denumire
		
					* PENTRU TAXARE INVERSA SI COMUNITATEA EUROPEANA: 4426 = 4427 PE LINIA DE TVA, ALTFEL CREDITORUL BAZEI
					Select introdc
					Replace cu_tva With 1
					*!* un singur rand T = fara ambiguitate de cota (factura abia creata, randul T din sablon)
					Count For doc_key == lcDocKey And tip_rand == 'T' To lnRanduriT
					Scan For doc_key == lcDocKey And tip_rand == 'T' And (lnRanduriT = 1 Or Nvl(ptva,0) = lnPtva)
						Replace id_jtva_coloana With lnId_jtva_coloanaTVA, ptva With lnCota_tva, ;
							explicatie_tva With lcExplicatie_TVA, cu_tva With 1
						If Seek(lnId_jtva_coloanaTVA, "cJtvaCol4427", "id_jtva")
							Replace scc With '4427', ascc With ''
						Else
							*!* creditorul propriu al randului T se pastreaza - se reface doar iesirea din 4427
							If Alltrim(Nvl(scc,'')) == '4427'
								Replace scc With lcSccS, ascc With lcAsccS
							Endif
						Endif
						Thisform.UpdateExplicatieSAFT()
					Endscan
				Endif
			Endif
		Endif
		*!* randul de discount urmeaza baza documentului: aceeasi cota, explicatie si taxa SAFT
		If lcTipRand <> 'T'
			Select introdc
			Replace id_jtva_coloana With tnIdJtvaColoana, ptva With lnPtva, ;
				explicatie_tva With lcExplicatieTva, taxcode With lnTaxCodeBaza, ;
				cu_tva With Iif(lnPtva = 0, 0, 1) ;
				For doc_key == lcDocKey And tip_rand == 'G'
		Endif
		
		Select introdc
		*!* pentru S, Locate cuprinde si scd - un document poate avea mai multe randuri S
		If lcTipRand == 'S'
			Locate For doc_key == lcDocKey And tip_rand == lcTipRand And scd == lcScd
		Else
			Locate For doc_key == lcDocKey And tip_rand == lcTipRand
		Endif
		
		Return .T.
	ENDPROC

	PROCEDURE assign_analitic
		*!* analiticul contului articolelor pe randul S (folosit de creeaza_rand_s)
		PARAMETERS tcCont,pcAct,pcRul
		
		PRIVATE pcCont,pcAct,pcRul,pParamP,pParamS
		STORE 0 TO pParamP,pParamS
		lcAnalitic = ''
		lcAlias = ALIAS()
		
		pcCont = ALLTRIM(tcCont)
		
		lcSel = [SELECT * from ] + gcs + [.config_analitice WHERE cont = ?pcCont]
		lcCursor = 'crs_cfg_ana'
		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		IF lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
			RETURN
		ENDIF
		
		IF lnSucces > 0
			IF RECCOUNT('crs_cfg_ana')=0
				USE IN crs_cfg_ana
				lnSucces = -1
			ENDIF
		ENDIF
		
		IF lnSucces > 0
			SELECT crs_cfg_ana
			SCATTER NAME ocfg
			lcCampPrefix = NVL(ALLTRIM(ocfg.camp_leg_prefix),'')
			lcCampSufix = NVL(ALLTRIM(ocfg.camp_leg_sufix),'')
		
			IF !EMPTY(lcCampPrefix)
				IF TYPE('&pcRul..'+lcCampPrefix) # 'U'
					pParamP = &pcRul..&lcCampPrefix
				ELSE
					IF TYPE('&pcAct..'+lcCampPrefix) # 'U'
						pParamP = &pcAct..&lcCampPrefix
					ENDIF
				ENDIF
			ENDIF
		
			IF !EMPTY(lcCampSufix)
				IF TYPE('&pcRul..'+lcCampSufix) # 'U'
					pParamS = &pcRul..&lcCampSufix
				ELSE
					IF TYPE('&pcAct..'+lcCampSufix) # 'U'
						pParamS = &pcAct..&lcCampSufix
					ENDIF
				ENDIF
			ENDIF
		
			lcSel = [{call fconturi_analitice(?gcs,?pcCont,0,?pParamP,?pParamS)}]
			lcCursor = 'crs_analitice'
			lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			ENDIF
		ENDIF
		
		&& iau Primul Simbol Analitic din Tabel - ordonat pt ca e selectat cu Distinct
		IF lnSucces > 0
			SELECT crs_analitice
			GO top
			lcAnalitic = ALLTRIM(acont)
		ENDIF
		
		&& verificare analiticului cu Planul de Conturi
		IF lnSucces > 0
			lcSel = [SELECT cont,acont from ] + gcs + [.vplcont_analitic WHERE cont = ?pcCont and acont = ?lcAnalitic and an = ?gnAn ]
			lcCursor = 'crs_verific'
			lnSucces = goExecutor.oExecute(lcSel,lcCursor)
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			ENDIF
		ENDIF
		
		IF lnSucces > 0
			IF RECCOUNT('crs_verific')=0
				lnSucces = -1
			ENDIF
		ENDIF
		
		IF USED('crs_cfg_ana')
			USE IN crs_cfg_ana
		ENDIF
		IF USED('crs_verific')
			USE IN crs_verific
		ENDIF
		IF USED('crs_analitice')
			USE IN crs_analitice
		ENDIF
		IF USED('crs_verific')
			USE IN crs_verific
		ENDIF
		
		IF lnSucces < 0
			lcAnalitic = ''
		ENDIF
		
		SELECT (lcAlias)
		RETURN lcAnalitic
	ENDPROC

	PROCEDURE calc_baze_cota_creditor
		*!* Grupeaza bazele articolelor (rul_temp) pe cota TVA + creditorul (scc/ascc) al S-ului
		*!* corespunzator contului articolului (scd==cont, ascd==acont); fara S pereche foloseste
		*!* scc/ascc din toFallback. Partenerul TVA (id_partc/partc pe T) ramane cel ales la
		*!* introducerea facturii. Rezultatul ramane deschis in crsGrupCota (cota_tva, scc, ascc,
		*!* baza_lei, baza_val) - apelantul face Use In crsGrupCota.
		Lparameters tcDocKey, toFallback
		Local lcSelCbcc
		lcSelCbcc = Select()
		
		Select scd As cont, ascd As acont, scc, ascc From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'S' Into Cursor crsSccPerCont READWRITE
		Select Distinct rul_temp.cont, rul_temp.acont From rul_temp Where !Deleted() Into Cursor crsContArt NOFILTER
		Select crsContArt
		Scan
			Select crsSccPerCont
			Locate For Alltrim(cont) == Alltrim(crsContArt.cont) And Alltrim(Nvl(acont,'')) == Alltrim(Nvl(crsContArt.acont,''))
			If !Found()
				Select crsSccPerCont
				Append Blank
				Replace cont With crsContArt.cont, acont With crsContArt.acont, scc With toFallback.scc, ascc With toFallback.ascc
			Endif
			Select crsContArt
		Endscan
		Use In crsContArt
		
		If This.lIntern
			Select rul_temp.cota_tva, crsSccPerCont.scc, crsSccPerCont.ascc, ;
				Sum(Round(rul_temp.pret_lei*rul_temp.cant,gnPc)) As baza_lei, 0 As baza_val ;
				From rul_temp Inner Join crsSccPerCont ;
				On Alltrim(rul_temp.cont) == Alltrim(crsSccPerCont.cont) And Alltrim(Nvl(rul_temp.acont,'')) == Alltrim(Nvl(crsSccPerCont.acont,'')) ;
				Where !Deleted("rul_temp") ;
				Group By rul_temp.cota_tva, crsSccPerCont.scc, crsSccPerCont.ascc ;
				Into Cursor crsGrupCota NOFILTER
		Else
			Select rul_temp.cota_tva, crsSccPerCont.scc, crsSccPerCont.ascc, ;
				Sum(Round(rul_temp.pret_val*rul_temp.cant,gnPval)) As baza_val, 0 As baza_lei ;
				From rul_temp Inner Join crsSccPerCont ;
				On Alltrim(rul_temp.cont) == Alltrim(crsSccPerCont.cont) And Alltrim(Nvl(rul_temp.acont,'')) == Alltrim(Nvl(crsSccPerCont.acont,'')) ;
				Where !Deleted("rul_temp") ;
				Group By rul_temp.cota_tva, crsSccPerCont.scc, crsSccPerCont.ascc ;
				Into Cursor crsGrupCota NOFILTER
		Endif
		Use In crsSccPerCont
		
		Select (lcSelCbcc)
	ENDPROC

	PROCEDURE calc_doc_key
		* cheia documentului: nr_doc identifica unic documentul (factura + rand TVA + eventual DVI);
		* serie_act/nract/id_fdoc/id_partc raman informative in cheie
		Return Alltrim(Str(Nvl(introdc.nr_doc,0),8)) + '|' + Upper(Alltrim(Nvl(introdc.serie_act,''))) + '|' + Alltrim(Str(Nvl(introdc.nract,0),14)) + '|' + ;
			Alltrim(Str(Nvl(introdc.id_fdoc,0),14)) + '|' + Alltrim(Str(Nvl(introdc.id_partc,0),14))
	ENDPROC

	PROCEDURE copiaza_valoare
		*!* Propaga valoarea campului tcCamp pe tot grupul doc_key; daca tcCamp face parte din
		*!* cheia documentului, doc_key se regenereaza pe grup dupa propagare.
		Lparameters tcCamp
		Local lcSelect, lcCursor, luValoare, lcDocKeyOld, lcDocKeyNou, lnRecCurent, llCheie
		Local llCampValuta, llCampIdentitate, llSursaProtejata, lcCamp
		lcCursor = Thisform.grid1.RecordSource
		lcSelect = Select()
		Select (lcCursor)
		lnRecCurent = Recno()
		lcDocKeyOld = doc_key
		luValoare = &tcCamp
		*!* la runtime VFP califica ControlSource-ul coloanei cu aliasul grilei (introdc.nract)
		lcCamp = Lower(Alltrim(tcCamp))
		If '.' $ lcCamp
			lcCamp = Substr(lcCamp, Rat('.', lcCamp) + 1)
		Endif
		llCheie = Inlist(lcCamp, 'serie_act', 'nract', 'id_fdoc', 'fdoc', 'id_partc', 'partc')
		llCampValuta = Inlist(lcCamp, 'in_valuta', 'id_valuta', 'nume_val', 'curs', 'suma_val')
		llCampIdentitate = Inlist(lcCamp, 'nract', 'serie_act', 'partc', 'id_partc', 'id_fdoc', 'fdoc', 'dataact')
		*!* randul DVI e protejat si ca SURSA - identitatea lui vamala nu se propaga pe factura-mama
		llSursaProtejata = (llCampValuta And Thisform.rand_protejat()) Or (llCampIdentitate And Nvl(rand_dvi,0) = 1)
		
		If !llSursaProtejata
			Scan For doc_key == lcDocKeyOld And Recno() <> lnRecCurent
				If llCampValuta And Thisform.rand_protejat()
					Loop
				Endif
				If llCampIdentitate And Nvl(rand_dvi,0) = 1
					Loop
				Endif
				Replace (tcCamp) With luValoare
			Endscan
		Endif
		
		If llCheie And !llSursaProtejata
			Go lnRecCurent
			lcDocKeyNou = Thisform.calc_doc_key()
			Scan For doc_key == lcDocKeyOld
				Replace doc_key With lcDocKeyNou
			Endscan
		Endif
		
		Go lnRecCurent
		Select (lcSelect)
		Release lcSelect, lcCursor, luValoare, lcDocKeyOld, lcDocKeyNou, lnRecCurent, llCheie
		Release llCampValuta, llCampIdentitate, llSursaProtejata, lcCamp
	ENDPROC

	PROCEDURE creeaza_rand_s
		*!* un rand S: copie completa a sablonului documentului (toSablon de la sparge_document,
		*!* altfel randul B/S gasit aici); suprascrie doar scd/ascd, suma/suma_val, tip_rand, mod_manual.
		*!* analiticul (tcAcont) vine de pe articole cand e furnizat, altfel din assign_analitic.
		Lparameters tcDocKey, tcCont, tnSumaLei, tnSumaVal, toSablon, tcAcont, tnCota
		Private loRandB, lcAcont
		Local lcSelAnt, lnIdJtvaS
		lcSelAnt = Select()
		Select introdc
		If Pcount() >= 5 And Vartype(toSablon) == 'O'
			loRandB = toSablon
		Else
			Locate For doc_key == tcDocKey And tip_rand == 'B'
			If !Found()
				Locate For doc_key == tcDocKey And tip_rand == 'S'
			Endif
			If !Found()
				Select (lcSelAnt)
				Return
			Endif
			Scatter Name loRandB Memo
		Endif
		Append Blank
		Gather Name loRandB Memo
		If Pcount() >= 6 And Vartype(tcAcont) == 'C'
			lcAcont = Alltrim(tcAcont)
		Else
			lcAcont = Thisform.assign_analitic(tcCont, Thisform.oact, 'loRandB')
		Endif
		Replace tip_rand With 'S', doc_key With tcDocKey, scd With tcCont, ascd With lcAcont, ;
			suma With tnSumaLei, suma_val With tnSumaVal, mod_manual With 0
		If Pcount() >= 7 And Vartype(tnCota) == 'N' And tnCota > 0 And tnCota <> Nvl(ptva,0)
			lnIdJtvaS = Thisform.gaseste_jtva_cota(Nvl(loRandB.id_jtva_coloana,0), tnCota)
			Replace ptva With tnCota
			If lnIdJtvaS <> 0
				Replace id_jtva_coloana With lnIdJtvaS
				Select jtva_coloane2
				Locate For id_jtva_coloana = lnIdJtvaS
				If Found()
					Replace explicatie_tva With jtva_coloane2.denumire In introdc
				Endif
				Select introdc
			Endif
		Endif
		Select (lcSelAnt)
	ENDPROC

	PROCEDURE Destroy
		USE IN (SELECT('cJtvaCol4427'))
	ENDPROC

	PROCEDURE disc_document
		*!* discountul (rand G) al documentului tcDocKey, in lei sau in valuta.
		Lparameters tcDocKey, tlValuta
		Local lcSelAnt, lnRecAnt, lnDisc
		lcSelAnt = Select()
		lnRecAnt = Recno('introdc')
		Select introdc
		If tlValuta
			Sum suma_val For doc_key == tcDocKey And tip_rand == 'G' To lnDisc
		Else
			Sum suma For doc_key == tcDocKey And tip_rand == 'G' To lnDisc
		Endif
		Select (lcSelAnt)
		If Between(lnRecAnt, 1, Reccount('introdc'))
			Go lnRecAnt In introdc
		Endif
		Return lnDisc
	ENDPROC

	PROCEDURE do_adauga
		*!* Deschide dialogul modal frm_adauga_factura. Memoria DVI (cDviSerie/cDviNr/dDviData/
		*!* nDviIdPartener/cDviPartener/nDviIdFdoc) traieste pe import_nota si e citita/scrisa
		*!* de dialog prin Thisform.oParinte.
		Local loDlg
		loDlg = Createobject('import_adauga_factura', Thisform)
		loDlg.Show(1)
		Release loDlg
		
	ENDPROC

	PROCEDURE do_adauga_articol
		*!* filtru pe conturile de clasa 2+3, independent de conturile deja prezente pe nota
		LOCAL lcXMLArticole, lcFiltru, lcCrsArt, lcCrsNir, lnPtvaPrincipal
		*!* filtrul intra in WHERE-ul Oracle prin cauta_nom_articole: sintaxa SQL, nu VFP.
		lcFiltru = [Substr(Trim(a.cont),1,1) In ('2','3')]
		lcXMLArticole = cauta_nom_articole(lcFiltru)	&& ocautare.prg - selectie multipla (click/SPACE); adauga singura a.inactiv = 0
		
		*!* cota_tva implicita a articolelor noi = ptva de pe primul rand de baza (B/S) al
		*!* facturii principale; randul T pereche poate fi al DVI-ului (alt document).
		lnPtvaPrincipal = 0
		SELECT introdc
		GO TOP
		LOCATE FOR Inlist(tip_rand,'B','S')
		IF FOUND()
			lnPtvaPrincipal = ptva
		ENDIF
		
		IF gnButon = 1 AND !EMPTY(lcXMLArticole)
			lcCrsArt = [crsArtAlese]
			XMLTOCURSOR(lcXMLArticole, lcCrsArt)
		
			lcCrsNir = THIS.gridart.RECORDSOURCE
			loAct = THIS.oact
		
			SELECT (lcCrsArt)
			SCAN
				SCATTER NAME loArt
				*!* articol fara cont in nomenclator - nu se adauga, restul continua
				IF EMPTY(ALLTRIM(NVL(loArt.cont,'')))
					amessagebox("Articolul " + ALLTRIM(loArt.denumire) + " nu are cont definit in nomenclator - nu a fost adaugat pe nota!",48,"Atentie")
					LOOP
				ENDIF
				SELECT (lcCrsNir)
				APPEND BLANK
				GATHER NAME loAct
				GATHER NAME loArt
				REPLACE id_gestiune WITH loAct.id_gestin, cota_tva WITH lnPtvaPrincipal
				SCATTER NAME lorul && pentru id_gestiune
				lcAcont = THISFORM.assign_analitic(lorul.CONT,THISFORM.oact,'lorul')
				SELECT (lcCrsNir)
				REPLACE acont WITH lcAcont, tva WITH ROUND(pret * (proc_tva-1), gnPpret)
				SELECT (lcCrsArt)
			ENDSCAN
			USE IN (lcCrsArt)
		
			THIS.gridart.REFRESH
		ENDIF
		
		THIS.gridart.cserie.SetFocus()
		Thisform.sincronizeaza()
	ENDPROC

	PROCEDURE do_adauga_factura
		*!* Cloneaza perechea-sablon (baza + TVA) din introdc_sablon, o adauga in introdc si o
		*!* populeaza cu datele documentului (toDlg). Identitatea randurilor e tip_rand+doc_key,
		*!* iar fiecare document primeste un nr_doc nou. toDlg.cTipTva in {'F' furnizor, 'D' DVI,
		*!* 'N' fara} decide randul de TVA. Cand exista discount (disc_baza_lei<>0), randul G se
		*!* creeaza intre randul B si randul T, cu aceleasi date de TVA ca baza.
		Lparameters toDlg
		Local lnSel, loBaza, loTva, lnNrDoc, lnRecT, llDviInValuta, lnDviTvaAsteptat
		Local lcIdValutaDvi, lnCursDvi, lcNumeValDvi, lnValutaProprie, lcDocKeyCrt
		lnSel = Select()
		If !Used('introdc_sablon') Or Reccount('introdc_sablon') < 2
			Messagebox('Lipseste perechea-sablon (introdc_sablon).', 0+16, 'Adauga factura')
			Select (lnSel)
			Return .F.
		Endif
		
		*!* urmatorul nr_doc; randurile D (99999999) sunt ignorate
		lnNrDoc = 0
		Select introdc
		If Reccount() > 0
			Calculate Max(Iif(Nvl(nr_doc,0) = 99999999, 0, Nvl(nr_doc,0))) To lnNrDoc
		Endif
		lnNrDoc = Max(Nvl(lnNrDoc,0), 0) + 1
		
		* --- rand BAZA (clona recordului 1 din sablon) ---
		Select introdc_sablon
		Go Top
		Scatter Name loBaza Memo
		Select introdc
		Append Blank
		Gather Name loBaza Memo
		Replace serie_act With toDlg.serie_act, ;
			nract With toDlg.nract, ;
			dataact With toDlg.dataact, ;
			fdoc With toDlg.fdoc, ;
			id_fdoc With toDlg.id_fdoc, ;
			id_partc With toDlg.id_partc, ;
			partc With toDlg.partc, ;
			explicatia With toDlg.explicatia, ;
			suma With toDlg.suma, ;
			suma_val With toDlg.suma_val, ;
			in_valuta With toDlg.in_valuta, ;
			participa_valuta With toDlg.participa_valuta, ;
			id_valuta With toDlg.id_valuta, ;
			curs With toDlg.curs, ;
			nume_val With toDlg.nume_val
		* tip_rand/nr_doc intai (Gather din sablon aduce tip_rand='B'); doc_key citeste nr_doc deja scris,
		* nu ordinea de evaluare in acelasi Replace
		Replace tip_rand With 'B', nr_doc With lnNrDoc
		Replace doc_key With Thisform.calc_doc_key(), suma_doc With toDlg.suma, suma_doc_val With toDlg.suma_val
		
		* --- rand DISCOUNT (rand G, intre B si T; clona randului B proaspat creat) ---
		If Type('toDlg.disc_baza_lei') <> 'U' And Round(Nvl(toDlg.disc_baza_lei,0), gnPC) <> 0
			Scatter Name loBaza Memo
			Append Blank
			Gather Name loBaza Memo
			Replace tip_rand With 'G', ;
				scd With loBaza.scc, ;
				ascd With loBaza.ascc, ;
				scc With '767', ;
				ascc With '', ;
				suma With toDlg.disc_baza_lei, ;
				suma_val With Iif(Type('toDlg.disc_baza_val')='U', 0, toDlg.disc_baza_val), ;
				id_partd With loBaza.id_partc, ;
				partd With loBaza.partc, ;
				id_partc With 0, ;
				partc With '', ;
				participa_valuta With .F., ;
				explicatia With 'DISCOUNT', ;
				mod_manual With 0, ;
				rand_dvi With 0, ;
				valuta_proprie With 0
		Endif
		
		* --- rand TVA (clona recordului 2 din sablon; suma TVA o pune do_executa) ---
		Select introdc_sablon
		Go 2
		Scatter Name loTva Memo
		Select introdc
		Append Blank
		Gather Name loTva Memo
		Replace serie_act With toDlg.serie_act, ;
			nract With toDlg.nract, ;
			dataact With toDlg.dataact, ;
			fdoc With toDlg.fdoc, ;
			id_fdoc With toDlg.id_fdoc, ;
			id_partc With toDlg.id_partc, ;
			partc With toDlg.partc, ;
			in_valuta With toDlg.in_valuta, ;
			participa_valuta With toDlg.participa_valuta, ;
			id_valuta With toDlg.id_valuta, ;
			curs With toDlg.curs, ;
			nume_val With toDlg.nume_val
		* tip_rand/nr_doc/doc_key - vezi comentariul de la randul BAZA
		Replace tip_rand With 'T', nr_doc With lnNrDoc
		Replace doc_key With Thisform.calc_doc_key(), suma_doc With toDlg.suma, suma_doc_val With toDlg.suma_val
		lnRecT = Recno()
		lcDocKeyCrt = doc_key
		
		Do Case
		Case toDlg.cTipTva = 'F'
			* explicatia TVA + comutarea 4426=4427/401, ca la editarea in grid (aplica_explicatie_tva);
			* metoda asteapta randul curent pe un rand non-T (B) - repozitionez pe baza (Locate, nu Skip -1,
			* pentru ca randul G se poate afla intre B si T); aplica_explicatie_tva gaseste ea insasi
			* randul T prin doc_key. do_executa() face Go Top, deci pozitia finala nu conteaza.
			Locate For doc_key == lcDocKeyCrt And tip_rand == 'B'
			Thisform.aplica_explicatie_tva(toDlg.id_jtva_coloana)
		Case toDlg.cTipTva = 'D'
			* explicatia TVA in tandem (baza + linia de TVA), ca la editarea in grid (aplica_explicatie_tva);
			* apoi Replace-ul de mai jos suprascrie pe linia de TVA campurile proprii DVI-ului - doc_key ramane
			* al documentului-mama (nr_doc neschimbat), desi randul poarta partener/conturi de vama
			Locate For doc_key == lcDocKeyCrt And tip_rand == 'B'
			Thisform.aplica_explicatie_tva(toDlg.id_jtva_coloana)
			Select introdc
			*!* randul T al facturii curente, pe Recno-ul salvat la creare (Locate cu
			*!* calc_doc_key() in FOR se evalueaza per rand scanat => gasea primul T din cursor)
			Go lnRecT
			llDviInValuta = Iif(Type('toDlg.dvi_in_valuta') = 'U', (toDlg.dvi_tva_val <> 0), toDlg.dvi_in_valuta)
			lcIdValutaDvi = Iif(Type('toDlg.dvi_id_valuta') = 'U', toDlg.id_valuta, toDlg.dvi_id_valuta)
			lnCursDvi = Iif(Type('toDlg.dvi_curs') = 'U', toDlg.curs, toDlg.dvi_curs)
			lcNumeValDvi = Iif(Type('toDlg.dvi_nume_val') = 'U', toDlg.nume_val, toDlg.dvi_nume_val)
			lnValutaProprie = Iif(Type('toDlg.dvi_valuta_proprie') = 'U', 0, toDlg.dvi_valuta_proprie)
			lnDviTvaAsteptat = Round((toDlg.suma - Iif(Type('toDlg.disc_baza_lei') = 'U', 0, Nvl(toDlg.disc_baza_lei, 0))) * ptva / 100, gnPC)
			* TVA platit in vama: randul de TVA devine "al DVI-ului" - alt document/partener/conturi
			Replace serie_act With toDlg.dvi_serie, ;
				nract With toDlg.dvi_nract, ;
				dataact With toDlg.dvi_dataact, ;
				fdoc With toDlg.dvi_fdoc, ;
				id_fdoc With toDlg.dvi_id_fdoc, ;
				id_partc With toDlg.dvi_id_partc, ;
				partc With toDlg.dvi_partc, ;
				scd With '4426', ;
				scc With toDlg.dvi_scc, ;
				suma With toDlg.dvi_tva_lei, ;
				suma_val With Iif(llDviInValuta, toDlg.dvi_tva_val, 0), ;
				in_valuta With Iif(llDviInValuta, 1, 0), ;
				participa_valuta With Iif(llDviInValuta, toDlg.participa_valuta, .F.), ;
				id_valuta With Iif(llDviInValuta, lcIdValutaDvi, 0), ;
				curs With Iif(llDviInValuta, lnCursDvi, 0), ;
				nume_val With Iif(llDviInValuta, lcNumeValDvi, ''), ;
				rand_dvi With 1, ;
				valuta_proprie With lnValutaProprie, ;
				mod_manual With Iif(Round(Nvl(toDlg.dvi_tva_lei, 0), gnPC) <> lnDviTvaAsteptat, 1, 0)
		Case toDlg.cTipTva = 'N'
			* fara TVA: randul pereche ramane gol fiscal, ca la cota 0 in logica existenta
			Replace id_jtva_coloana With 0, ptva With 0, cu_tva With 0, explicatie_tva With ''
		Endcase
		
		Thisform.do_executa()
		Thisform.sincronizeaza()
		Select (lnSel)
		Return .T.
	ENDPROC

	PROCEDURE do_calculeaza_diferente
		PARAMETERS tnRecNo, tcCursor	&&	modificare v 2.1.3 : am adaugat tcCursor (tnRecNo nefolosit la pozitionare - vezi lnRecCrt)
		*!*	modificare	v 2.1.3
		*!*	lcSel = Thisform.gridart.RecordSource
		If Empty(tcCursor)
			lcSel = Thisform.gridart.RecordSource
		Else
			lcSel = tcCursor
		Endif
		*!*	modificare	v 2.1.3	^
		SELECT (lcSel)
		If Eof() Or Bof()
			lnRecCrt = 0
		Else
			lnRecCrt = Recno()
		Endif
		SUM ROUND(Pret*cant,gnPc) TO lnLeiTot
		SUM ROUND(Pretd*cant,gnPval) TO lnValTot
		
		*!* baza doar din documentele participante la pret; randul D manual se pastreaza (ca in recalc_diferente)
		If Used('introdc')
			lnRecIntr = Iif(Eof('introdc') Or Bof('introdc'), 0, Recno('introdc'))
			Select introdc
			Locate For tip_rand == 'D' And Nvl(mod_manual,0) = 1
			If Found()
				thisform.ndif_lei = suma
			Else
				Sum suma For Inlist(tip_rand,'B','S') And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) And participa_valuta To lnBazaParticipa
				thisform.ndif_lei = Round(lnBazaParticipa - lnLeiTot, gnPc)
			Endif
			If lnRecIntr > 0
				Try
					Go lnRecIntr In introdc
				Catch
					Go Top In introdc
				Endtry
			Endif
		Else
			thisform.ndif_lei = thisform.nbaza_lei - lnLeiTot
		Endif
		thisform.ndif_val = 0	&& diferenta doar in lei (randul D fara valuta) 
		thisform.TxtDifLei.Refresh 
		thisform.TxtDifVal.Refresh 
		If Vartype(Thisform._grdfooter1) = 'O'
			Thisform._grdfooter1.calcTotal()
		Endif
		
		SELECT (lcSel)
		If lnRecCrt > 0
			TRY 
				GO lnRecCrt
			CATCH 
				GO TOP 
			ENDTRY 
		Else
			LOCATE 
		Endif 
		
	ENDPROC

	PROCEDURE do_calculeaza_suma
		aMESSAGEBOX("Eroare calculeaza suma!")
		*!*	Local lnSuma1, lnSuma2, Tsuma, Tprocent, lnRec
		*!*	Store 0 To lnSuma1, lnSuma2, Tsuma, Tprocent, lnRec
		
		*!*	lcSel = Thisform.grid1.RecordSource
		
		*!*	Select (lcSel)
		*!*	lnRec = Recno(lcSel)
		*!*	Go Top
		*!*	lnSuma1 = suma
		*!*	If in_valuta = 1
		*!*		lnBazaVal = suma_val
		*!*	Endif
		*!*	Sum suma For in_valuta = 1 To lnBazaLei
		*!*	Sum suma_val For in_valuta = 1 To tSumaVal
		
		*!*	If Mod(Recno(),2)<>0 && rand impar
		*!*		lnSuma2 = suma
		*!*		lnSuma_val = suma_val
		*!*		If in_valuta = 0
		*!*			Replace explicatia4 With Allt(Str(lnSuma2/lnBazaLei*100,8,4)), explicatia5 With ''
		*!*		Else
		*!*			Replace explicatia5 With Allt(Str(lnSuma_val/lnBazaVal*100,8,4)), explicatia4 With ''
		*!*		Endif
		*!*	Else
		*!*		If ptva <> 0
		*!*			Repl suma With Round(lnSuma2*ptva/100,gnZvama)
		*!*			If in_valuta = 1
		*!*				Replace suma_val With Round(lnSuma_val*ptva/100,gnPval)
		*!*			Endif
		*!*		Else
		*!*			If Recno()>1 And !Eof()
		*!*				Repl suma With 0, suma_val With 0
		*!*			Endif
		*!*		Endif
		*!*	Endif
		*!*	Tprocent = Tprocent + Round(lnSuma2/lnSuma1*100,2)
		*!*	Tsuma = Tsuma + suma
		
		
		*!*	Goto lnRec
		
		*!*	Thisform.text2.Value = Tsuma
		*!*	Thisform.text3.Value = tSumaVal
		*!*	Thisform.Refresh
		
		
	ENDPROC

	PROCEDURE do_copiaza_nota
		*!* Buton copiere: meniu linie/document, ca la stergere (randul D nu se copiaza -
		*!* e rand unic pe document). Copia primeste nr_doc nou (F1, ca la do_adauga_factura)
		*!* si doc_key nou (calc_doc_key); seria/numarul/partenerul raman cele originale -
		*!* utilizatorul le editeaza apoi in grila (doc_key ramane unic prin nr_doc).
		Local lnSel, lnRaspuns, lcDoc, lcDocKey, lcTipRand, lnNrDoc, lcDocKeyNou, lnI, lnCnt, lnRecnoNou, loRec, lnRecnoCrt
		Local laRecno[1]
		lnSel = Select()
		Select introdc
		If Reccount() = 0 Or Eof() Or Bof()
			Select (lnSel)
			Return
		Endif
		lcTipRand = tip_rand
		If lcTipRand == 'D'
			amessagebox('Randul DIFERENTE nu se copiaza (e rand unic pe nota).', 0+48, 'Copiere')
			Select (lnSel)
			Return
		Endif
		lcDocKey = doc_key
		lnRecnoCrt = Recno()
		lcDoc = Alltrim(Nvl(fdoc,'')) + ' ' + Alltrim(Nvl(serie_act,'')) + ' ' + ;
			Alltrim(Str(Nvl(nract,0),14)) + ' - ' + Alltrim(Nvl(partc,''))
		lnRaspuns = amessagebox('Copiati nota ' + Alltrim(lcDoc) + Chr(13)+Chr(10) + ;
			'Da = tot documentul (toate randurile lui)' + Chr(13)+Chr(10) + ;
			'Nu = doar linia curenta', 3+32, 'Copiere')
		If !Inlist(lnRaspuns, 6, 7)
			Select (lnSel)
			Return
		Endif
		
		*!* urmatorul nr_doc (F1) - ca la do_adauga_factura
		lnNrDoc = 0
		If Reccount() > 0
			Calculate Max(Iif(Nvl(nr_doc,0) = 99999999, 0, Nvl(nr_doc,0))) To lnNrDoc
		Endif
		lnNrDoc = Max(Nvl(lnNrDoc,0), 0) + 1
		lcDocKeyNou = ''
		
		If lnRaspuns = 6
			*!* colectez intai recno-urile B/G/T (nu S - se regenereaza la sincronizare), abia apoi
			*!* copiez pe array: indexul ord_doc ar baga randurile noi in parcurgere daca as copia in Scan
			lnCnt = 0
			Scan For doc_key == lcDocKey And Inlist(tip_rand,'B','G','T')
				lnCnt = lnCnt + 1
				Dimension laRecno[lnCnt]
				laRecno[lnCnt] = Recno()
			Endscan
			For lnI = 1 To lnCnt
				Go laRecno[lnI]
				Scatter Name loRec Memo
				Append Blank
				Gather Name loRec Memo
				Replace nr_doc With lnNrDoc, mod_manual With 0, rand_dvi With 0, valuta_proprie With 0
				lnRecnoNou = Recno()
				If Empty(lcDocKeyNou) And tip_rand == 'B'
					lcDocKeyNou = Thisform.calc_doc_key()
				Endif
			Endfor
			*!* document fara rand B (doar T) - cheia se calculeaza pe ultimul rand copiat
			If Empty(lcDocKeyNou) And lnCnt > 0
				Go lnRecnoNou
				lcDocKeyNou = Thisform.calc_doc_key()
			Endif
			Replace doc_key With lcDocKeyNou For nr_doc == lnNrDoc
			Locate For doc_key == Padr(lcDocKeyNou, Len(doc_key))
		Else
			*!* copie linie: un singur rand
			*!* Calculate muta pointerul la EOF - revin pe linia sursa
			Go lnRecnoCrt
			Scatter Name loRec Memo
			Append Blank
			Gather Name loRec Memo
			Replace nr_doc With lnNrDoc, mod_manual With 0, rand_dvi With 0, valuta_proprie With 0
			Replace doc_key With Thisform.calc_doc_key()
		Endif
		
		Thisform.do_executa()
		Thisform.sincronizeaza()
		Select (lnSel)
	ENDPROC

	PROCEDURE do_copie
		lcSelect = this.gridart.RecordSource
		SELECT (lcSelect)
		SCATTER NAME loRec
		
		INSERT INTO (lcSelect) FROM NAME loRec
		this.do_reface()
		this.gridart.SetFocus()
		
	ENDPROC

	PROCEDURE do_executa
		Local lnSuma1, lnSuma2, lnSuma_val, Tsuma
		Store 0 To lnSuma1, lnSuma2, lnSuma_val, Tsuma
		LOCAL lnBazaVal, tSumaVal, lnBazaLei, lcDocKeyRec, lcTipRandRec, lcDocKeyCrt, lnDiscTotalLei, lnDiscTotalVal
		lnBazaVal = 0
		tSumaVal = 0
		Sele introdc
		*!* pozitia curenta se salveaza pe doc_key+tip_rand, nu pe numarul de inregistrare
		lcDocKeyRec = ''
		lcTipRandRec = ''
		If Reccount() > 0 And Between(Recno(), 1, Reccount())
			lcDocKeyRec = doc_key
			lcTipRandRec = tip_rand
		Endif
		Go Top
		lnSuma1 = suma
		&& baza in valuta pentru facturile din import este pe prima linie
		If in_valuta = 1
			lnBazaVal = suma_val
		Endif
		
		&& baza lei pentru facturile interne este pe prima linie
		IF this.lIntern 
			lnBazaLei = IIF(participa_valuta, suma, 0)
		ELSE
			Sum suma For participa_valuta AND in_valuta = 1 AND scd <> '4426' To lnBazaLei
		ENDIF 	
		
		
		Sum suma_val For in_valuta = 1 And tip_rand<>'G' To tSumaVal
		Sum suma For tip_rand = 'G' To lnDiscTotalLei
		Sum suma_val For tip_rand = 'G' To lnDiscTotalVal
		
		*!*lnBazaLei = suma && adaugata 06.09.2007 marius.mutu - mi-e neclar fata de ce suma se calculeaza procentele
		&& procentele se recalculeaza oricum in ointroduceri.prg
		
		
		*!* Scan doar pe randurile B; randul T al fiecarui document se cauta prin Locate pe doc_key
		Scan For tip_rand = 'B'
			lnSuma2 = suma - Thisform.disc_document(doc_key, .F.)
			lnSuma_val = suma_val - Thisform.disc_document(doc_key, .T.)
		*REPL explicatia4 WITH ALLT(STR(lnSuma2/lnSuma1*100,6,2))+'%'
		*!*			If in_valuta = 0
			*!* procentele per rand (explicatia4/explicatia5) le scrie sincronizeaza(), dupa spargere - nu aici
			*!*	modificare	v 2.1.39
			*!*	modificare	v 2.1.39	^
			Tsuma = Tsuma + suma
			
			lcDocKeyCrt = doc_key
			Locate For doc_key == lcDocKeyCrt And tip_rand = 'T'
			If Found()
				*!* rand T marcat manual (mod_manual=1) - nu se rescrie suma/suma_val
				If Nvl(mod_manual,0) <> 1 And !Thisform.rand_protejat()
					If ptva <> 0
						IF lnSuma2 <> 0
							Repl suma With Round(lnSuma2*ptva/100,gnPC)
						ENDIF 	
						If in_valuta = 1 AND lnSuma_val <> 0
							Replace suma_val With Round(lnSuma_val*ptva/100,gnPval)
						Endif
					Else
						Repl suma With 0, suma_val With 0
					Endif
				Endif
				Tsuma = Tsuma + suma
			Endif
		Endscan
		
		*!*	IF MOD(RECNO(),2)<>0
		*!*			suma2=suma
		*!*			REPLACE explicatia4 WITH ALLT(STR(suma2/suma1*100,6,3)+'%')
		*!*			SKIP 1
		*!*			IF ptva # 0
		*!*				REPLACE suma WITH ROUND(suma2*ptva /100,gnPc)
		*!*				REPLACE suma_val WITH ROUND(suma_val*ptva /100,gnPval)
		*!*			ELSE
		*!*				REPLACE suma WITH 0, suma_val WITH 0
		*!*			ENDIF
		*!*	*!*		ENDIF
		*!*	ENDIF
		
		*!* repozitionare finala pe doc_key+tip_rand, fallback Go Top
		Do Case
		Case lcTipRandRec == 'D'
			*!* randul D are doc_key gol - repozitionare dupa tip_rand
			Locate For tip_rand == 'D'
			If !Found()
				Go Top
			Endif
		Case !Empty(lcDocKeyRec)
			Locate For doc_key == lcDocKeyRec And tip_rand == lcTipRandRec
			If !Found()
				Go Top
			Endif
		Otherwise
			Go Top
		Endcase
		
		
		Tsuma = Tsuma - lnDiscTotalLei
		tSumaVal = tSumaVal - lnDiscTotalVal
		Thisform.text2.Value = Tsuma
		Thisform.text3.Value = tSumaVal
		Thisform.refac_culori_documente()
		Thisform.Refresh
		
		
	ENDPROC

	PROCEDURE do_executa_pret
		PARAMETERS tnNivel, tRecNo, tnValue, tcCursor	&&	modificare v 2.1.3 : am adaugat tcCursor
		*!*	DEBUG
		*!*	SUSPEND 
		*!*	modificare	v 2.1.3
		*!*	lcSel = Thisform.gridart.RecordSource
		If Empty(tcCursor)
			lcSel = Thisform.gridart.RecordSource
		Else
			lcSel = tcCursor
		Endif
		*!*	modificare	v 2.1.3	^
		SELECT (lcSel)
		IF tnNivel <= 2
			*WAIT WINDOW STR(tnValue,16,4)
			IF this.lIntern
				IF tnNivel <= 1
					lnPretLei = ROUND(tnValue*thisform.procent_lei/100,gnPPret)			&&	modificare	v 2.1.39 : gnPPret in loc de gnPVal
				ELSE 
					lnPretLei = tnValue
				ENDIF 
				&&	modificare	v 2.1.39 : gnPPret in loc de gnPVal
				lnPretLei = ROUND(lnPretLei - (lnPretLei * proc_disc/100 ),gnPPret)		&&	modificare	v 2.1.37
				REPLACE pret WITH lnPretLei
			ELSE 		
				IF tnNivel <= 1
					lnPretVal = ROUND(tnValue*thisform.procent_val/100,gnPPretval)		&&	modificare	v 2.1.39 : gnPPretval in loc de gnPVal
				ELSE 
					lnPretval = tnValue
				ENDIF 
				lnPretVal = ROUND(lnPretVal - (lnPretVal * proc_disc/100 ),gnPPretval)	&&	modificare	v 2.1.39 : gnPPretval in loc de gnPVal
				REPLACE pretd WITH lnPretval
				
				*!* cursul documentului e oact.Curs (ncurs exista doar pe import_nir)
				lnPretLei = ROUND(ROUND(lnPretval*thisform.oact.Curs,gnPpret)*thisform.procent_lei/100,gnPpret)
				REPLACE pret WITH lnPretLei
			ENDIF 	
		ENDIF 
		
		this.do_calculeaza_diferente(tRecNo,tcCursor)	&&	modificare v 2.1.3 : am adaugat tcCursor
		*!* sincronizare amanata - nu se apeleaza direct din Valid/LostFocus de grid
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE do_modifica_explicatie_tva
		*!* cautare explicatie TVA prin formular (model: frm_modific2024 din omodificari.vcx);
		*!* logica de aplicare pe cursor e extrasa in aplica_explicatie_tva() - comuna cu
		*!* Grid1.cExplicatieTva.Combo1.Valid si cu frm_adauga_factura (ramura furnizor).
		LOCAL lnId, loCauta, lnCotaFiltru, lcFiltruTva
		
		Select introdc
		
		* filtrez explicatiile dupa procentul de TVA al liniei (coloana "TVA %");
		* fara procent (0/gol) se afiseaza toate, ca sa nu ramana lista goala
		lnCotaFiltru = Nvl(introdc.ptva, 0)
		lcFiltruTva = [id_jtva_coloana > 0]
		If lnCotaFiltru > 0
			lcFiltruTva = lcFiltruTva + [ and cota_tva = ] + Alltrim(Str(lnCotaFiltru,10,2))
		Endif
		
		* lista contine si liniile de baza si perechile de TVA, ca vechiul dropdown (jtva_coloane2) -
		* caut_explicatie_tva cu tlTipEx intoarce doar perechile de TVA, deci apelez direct cauta_alfa
		loCauta = cauta_alfa([select id_jtva_coloana, denumire, cota_tva FROM vjtva_coloane], [1=2], [], ;
			[denumire], [denumire,cota_tva], [Alegeti explicatia TVA], [Explicatie TVA,Cota TVA], ;
			[], .F., lcFiltruTva)
		
		If Vartype(loCauta) <> 'O' Or Empty(Nvl(loCauta.id_jtva_coloana,0))
			Return
		Endif
		
		lnId = loCauta.id_jtva_coloana
		
		Select introdc
		Thisform.aplica_explicatie_tva(lnId)
		
		Thisform.do_executa()
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE do_modifica_fdoc
		Local loCauta
		loCauta = caut_fdoc(.F.,.T.)
		If !Isnull(loCauta)
			Select (Thisform.grid1.RecordSource)
			Replace id_fdoc With loCauta.id_fdoc,fdoc With loCauta.fel_document
			Thisform.copiaza_valoare([id_fdoc])
			Thisform.copiaza_valoare([fdoc])
		Endif
	ENDPROC

	PROCEDURE do_modiparam
		Local lcSelect, lcFisier, lnIdArticol, lcCursor, lcCont, loAct, lnInregistrari, lnPtvaPrincipal
		LOCAL loEx as Exception 
		Local lcAcont, lcDenumire, lcSelect2, lcSql, llSucces, lnSucces, loArticol
		Local lcMesaj
		Local lnRec
		Local lnInStoc
		Private pnIdArticol, lorul
		loAct = This.oact
		*!* cota_tva implicita = ptva de pe primul rand de baza (ca la do_adauga_articol)
		lnPtvaPrincipal = 0
		SELECT introdc
		GO TOP
		LOCATE FOR Inlist(tip_rand,'B','S')
		IF FOUND()
			lnPtvaPrincipal = ptva
		ENDIF
		
		CALCULATE CNT() FOR !DELETED() TO lnInregistrari  IN rul_temp
		
		If m.lnInregistrari > 0
			IF AMESSAGEBOX('Doriti sa stergeti reperele deja existente?',4+32,_screen.Caption) = 6
				SELECT rul_temp
				DELETE ALL
			ENDIF 
		*!*		amessagebox("Nu puteti face import daca ati adaugat deja repere pe nir!",48,"Atentie")
		*!*		Return
		Endif
		amessagebox("Fisierul XLS trebuie sa contina campurile (in aceasta ordine si fara capul de tabel): " + CHR(13) + CHR(10) + ;
		[COD PRODUS, DENUMIRE, UM, CANTITATE, PRET IN VALUTA FARA TVA (de pe factura)] + Chr(13) + Chr(10) + Chr(13) + Chr(10) + ;
		[Fisierul trebuie sa fie salvat cu formatul "Microsoft Excel 5.0/95 Workbook (*.xls)"] ,48,"Atentie")
		
		lcFisier = Getfile("xls","Fisier factura","Alegeti",0,"Import fisier factura - format XLS")
		If Empty(m.lcFisier) Or !File(m.lcFisier)
			Return
		ENDIF
		lcSelect = "rul_temp"
		llSucces = .F.
		TRY
			SELECT 0
			Import From (lcFisier) Type Xls
			lcSelect2 = Alias()
			SELECT ALLTRIM(UPPER(TRANSFORM(a))) as codmat, UPPER(ALLTRIM(TRANSFORM(b))) as denumire, UPPER(ALLTRIM(TRANSFORM(c))) as um, ROUND(d,6) as cant, ROUND(e,6) as pret_val ;
				FROM &lcSelect2 ;
				INTO CURSOR crsImport
			llSucces = .T.
		Catch To loEx
			lcMesaj = 'Fisierul ' + m.lcFisier + ' nu a putut fi importat.' + Chr(13) + Chr(10) + TRANSFORM(loEx.ErrorNo) + " "
			IF loEx.ErrorNo = 1661
				lcMesaj = m.lcMesaj + [Salvati fisierul in formatul "Microsoft Excel 5.0/95 Workbook (*.xls)"]
			ELSE
				lcMesaj = m.lcMesaj + loEx.Message
			ENDIF 	
			amessagebox(m.lcMesaj, 0+48, _Screen.Caption)
		ENDTRY
		IF !m.llSucces
			RETURN
		ENDIF 
		USE IN (SELECT(m.lcSelect2))
		lcSelect2 = "crsImport"
		*!*	A	=	codmat
		*!*	B	=	denumire
		*!*	C	=	um
		*!*	D	=	cantitate
		*!*	E	=	pret achizitie in valuta
		
		
		save_grid_tag(Thisform.gridart)
		
		Select Distinct scd From actactan Where Inlist(Left(Alltrim(scd),1),'2','3') And suma <> 0 Into Cursor tconturi
		If Reccount('tconturi') = 1
			Select tconturi
			lcCont = Alltrim(scd)
		Else
			lcCont = []
		Endif
		Use In tconturi
		
		If Reccount(m.lcSelect2) > 0
			lcCursor = [crstmpimpart]
			Select (lcSelect2)
			Scan
				Scatter Name loArticol
				If !Empty(Nvl(loArticol.cant,0))
					pnIdArticol = 0
					lcSql = [select id_articol,denumire,in_stoc,cont from nom_articole where UPPER(codmat) = '] + loArticol.codmat + [' and sters = 0]
					If !goExecutor.oExecuta(lcSql,lcCursor)
						amessagebox("A fost inregistrata o eroare la cautarea articolului " + loArticol.denumire + " pe nir!" + crlf + ;
							"Iesiti din acest nir si reincercati operatia de preluare a fisierului!",48,"Atentie")
						Exit
					Else
						Select (lcCursor)
						If Reccount(lcCursor) > 0
							Locate For Upper(Alltrim(denumire)) = loArticol.denumire
							If !Found()
								Go Top
							Endif
							lcDenumire = Upper(Alltrim(denumire))
							If lcDenumire <> loArticol.denumire
								If amessagebox("Articolul " + loArticol.denumire + " a fost gasit in baza de date dupa cod material, dar are denumirea de "+;
										lcDenumire + ".Doriti sa pastrati denumirea din baza de date?" + crlf + ;
										"( Daca apasati nu, atunci se va crea un articol nou cu denumirea din fisier )",4+32,"Denumire diferita") = 6
									lnIdArticol = id_articol
									lnInStoc = Nvl(in_stoc,1)
									loArticol.denumire = m.lcDenumire
								Else
		*!*adauga_articol
									If Empty(m.lcCont)
										lcCont = Inputbox("Introduceti contul pentru articolul " + loArticol.denumire, "Cont articol ", m.lcCont, 5000,[371],[371])
									Endif
									lcSql = [begin pack_preturi.adauga_articol(?gnAn,'] + loArticol.codmat + [',NULL,NULL,] + ;
										['] + loArticol.denumire + [','] + loArticol.um + [',] + ;
										['] + Upper(Alltrim(m.lcCont)) + [',Null,0,0,NULL,NULL,0,NULL,1,0,0,?gnIdUtil,] + ;
										ALLTRIM(Str(loAct.id_partc)) + [,0,0,?@pnIdArticol); end;]
									goExecutor.oExecuta(lcSql)
									lnIdArticol = m.pnIdArticol
									lnInStoc = 1
								Endif
							Else
								lnIdArticol = id_articol
								lnInStoc = Nvl(in_stoc,1)
							Endif
						Else
		*!*	adauga articol
							If Empty(m.lcCont)
								lcCont = Inputbox("Introduceti contul pentru articolul " + loArticol.denumire, "Cont articol ", m.lcCont, 5000,[371],[371])
							Endif
							lcSql = [begin pack_preturi.adauga_articol(?gnAn,'] + loArticol.codmat + [',NULL,NULL,] + ;
								['] + loArticol.denumire + [','] + loArticol.um + [',] + ;
								['] + Upper(Alltrim(m.lcCont)) + [',Null,0,0,NULL,NULL,0,NULL,1,0,0,?gnIdUtil,] + ;
								ALLTRIM(Str(loAct.id_partc)) + [,0,0,?@pnIdArticol); end;]
							goExecutor.oExecuta(lcSql)
							lnIdArticol = m.pnIdArticol
							lnInStoc = 1
						Endif
						If lnIdArticol = 0
							amessagebox("A fost inregistrata o eroare la adaugarea articolului " + loArticol.denumire + " pe NIR!" + crlf + ;
								"Iesiti din acest nir si reincercati operatia de preluare a fisierului!",48,"Atentie")
							Exit
							Use In (lcCursor)
						Else
		*!*	completez in rul_temp
							Select (lcSelect)
							Append Blank
							Gather Name loAct
							Replace Cont With m.lcCont, id_gestiune With loAct.id_gestin, id_articol With m.lnIdArticol,;
								denumire With loArticol.denumire, codmat With loArticol.codmat,;
								um With loArticol.um, cant With loArticol.cant, pret_val With loArticol.pret_val,;
								in_stoc With m.lnInStoc, cota_tva With lnPtvaPrincipal
							Scatter Name lorul
							lcAcont = Thisform.assign_analitic(lorul.Cont, Thisform.oact, 'lorul')
							Select (m.lcSelect)
							Replace acont With m.lcAcont, tva With Round(Pret * (proc_tva-1), m.gnPpret)
							Thisform.do_executa_pret(1, Recno(), pret_val, m.lcSelect)
							Use In (m.lcCursor)
						Endif
					Endif
				Endif
				Select (m.lcSelect2)
			Endscan
		Endif
		Use In (select(lcSelect2))
		
		Select (lcSelect)
		GO TOP 
		lnRec = RECNO()
		thisform.Do_calculeaza_diferente(m.lnRec, m.lcSelect) 
		
		restore_grid_tag(Thisform.gridart)
		this.gridart.SetFocus()
		Thisform.sincronizeaza()
		 
	ENDPROC

	PROCEDURE do_reface
		lcSel = Thisform.gridart.RecordSource
		Select (lcSel)
		lnNrIreg = Reccount(lcSel)
		lnRec = Recno()
		lnLeiTot = 0
		lnValTot = 0
		
		i = 0
		Scan
			i = i + 1
			Scatter Name orul
		*!*	modificare	v 2.1.37
		*!*		lnPretval = Round(orul.pret_val*Thisform.procent_val/100,gnPval)
		*!*		lnPretval = Round(lnPretval - (lnPretval * orul.proc_disc/100 ),gnPval)
		*!*		lnPretLei = Round(Round(lnPretval*Thisform.ncurs,gnPpret)*Thisform.procent_lei/100,gnPpret)
			If Thisform.lIntern
				lnPretlei = Round(orul.pret_lei*Thisform.procent_lei/100,gnPPret)			&&	modificare	v 2.1.39 : gnPPret in loc de gnPVal
				lnPretlei = Round(lnPretlei - (lnPretlei * orul.proc_disc/100 ),gnPPret)	&&	modificare	v 2.1.39 : gnPPret in loc de gnPVal
				lnPretval = 0
			Else
				lnPretval = Round(orul.pret_val*Thisform.procent_val/100,gnPPretVal)		&&	modificare	v 2.1.39 : gnPPretVal in loc de gnPVal
				lnPretval = Round(lnPretval - (lnPretval * orul.proc_disc/100 ),gnPPretVal)	&&	modificare	v 2.1.39 : gnPPretVal in loc de gnPVal
				*!* cursul documentului e oact.Curs (ncurs exista doar pe import_nir)
				lnPretlei = Round(Round(lnPretval*Thisform.oact.Curs,gnPpret)*Thisform.procent_lei/100,gnPpret)
			Endif
		*!*	modificare	v 2.1.37	^
			Replace pretd With lnPretval
			Replace Pret With lnPretlei
			lnLeiTot = lnLeiTot + Round(lnPretlei*cant,gnPc)
			lnValTot = lnValTot + Round(lnPretval*cant,gnPval)
		*!*		IF i = lnNrIreg
		*!*			REPLACE pret WITH pret + (thisform.nbaza_lei - lnPretTot)
		*!*		ENDIF
		
		Endscan
		
		
		Thisform.Do_calculeaza_diferente(lnRec)
		
		*!* repozitionare explicita - do_calculeaza_diferente ramane pe pozitia de la intrare (aici EOF)
		Select (lcSel)
		If lnRec > 0
			Try
				Go lnRec
			Catch
				Go Top
			Endtry
		Else
			Go Top
		Endif
	ENDPROC

	PROCEDURE do_sterge
		*!* Butonul de stergere: linia curenta sau nota (document) curenta din introdc.
		*!* Randul D (fara document propriu, rand unic) pastreaza confirmarea simpla.
		*!* Pentru restul, meniu Da=document (toate randurile B+S*+T cu acelasi doc_key,
		*!* identitatea documentului), Nu=doar linia curenta, Cancel=renunta. Cu SET DELETED ON
		*!* randurile sterse dispar din grid si din Scan/Sum-urile din flux. Nu se face
		*!* Zap + refacere: introdc e sursa grid-ului, iar Zap inchide si recreeaza cursorul,
		*!* deci grid-ul ar ramane fara sursa (blank).
		Local lnSel, lnRaspuns, lcDoc, lcDocKey, lcTipRand
		lnSel = Select()
		Select introdc
		If Reccount() = 0 Or Eof() Or Bof()
			Select (lnSel)
			Return
		Endif
		lcDocKey = doc_key
		lcTipRand = tip_rand
		lcDoc = Alltrim(Nvl(fdoc,'')) + ' ' + Alltrim(Nvl(serie_act,'')) + ' ' + ;
			Alltrim(Str(Nvl(nract,0),14)) + ' - ' + Alltrim(Nvl(partc,''))
		If lcTipRand == 'D'
			lnRaspuns = amessagebox('Stergeti nota ' + Alltrim(lcDoc) + Chr(13) + Chr(10) + ;
				'(toate randurile documentului)?', 4+32, 'Stergere nota')
			If lnRaspuns <> 6
				Select (lnSel)
				Return
			Endif
			Delete
		Else
			lnRaspuns = amessagebox('Stergeti nota ' + Alltrim(lcDoc) + Chr(13)+Chr(10) + ;
				'Da = tot documentul (toate randurile lui)' + Chr(13)+Chr(10) + ;
				'Nu = doar linia curenta', 3+32, 'Stergere')
			Do Case
			Case lnRaspuns = 6
				Delete For doc_key == lcDocKey
			Case lnRaspuns = 7
				Delete
			Otherwise
				Select (lnSel)
				Return
			Endcase
		Endif
		Go Top
		Thisform.do_executa()
		Thisform.sincronizeaza()
		Select (lnSel)
	ENDPROC

	PROCEDURE do_sterge_articol
		*!* Sterge articolul curent de pe grila GridArt (rul_temp).
		Local lnSel, lnRaspuns, lcDenumire
		If !Used('rul_temp')
			Return
		Endif
		lnSel = Select()
		Select rul_temp
		If Reccount() = 0 Or Eof()
			Select (lnSel)
			Return
		Endif
		lcDenumire = Alltrim(Nvl(denumire,''))
		lnRaspuns = amessagebox('Stergeti articolul ' + lcDenumire + '?', 4+32, 'Stergere articol')
		If lnRaspuns <> 6
			Select (lnSel)
			Return
		Endif
		Delete
		Select (lnSel)
		This.gridart.Refresh()
		This.sincronizeaza()
	ENDPROC

	PROCEDURE gaseste_jtva_cota
		*!* Mapare cota -> id_jtva_coloana dupa semnatura coloanei (coloana_jc fara cifre, distinge baza de TVA).
		*!* tnIdJtvaFamilie = un id_jtva_coloana din familia sursa, tnCota = cota tinta.
		*!* Returneaza 0 daca nu gaseste.
		Lparameters tnIdJtvaFamilie, tnCota
		Local lcSel, lcSemnatura, lnGasit
		lnGasit = 0
		lcSel = Select()
		If Used('jtva_coloane2')
			Select jtva_coloane2
			Locate For id_jtva_coloana = tnIdJtvaFamilie
			If Found()
				lcSemnatura = Chrtran(Alltrim(Nvl(coloana_jc,'')),'0123456789','')
				If !Empty(lcSemnatura)
					Locate For Chrtran(Alltrim(Nvl(coloana_jc,'')),'0123456789','') == lcSemnatura And cota_tva = tnCota
					If Found()
						lnGasit = id_jtva_coloana
					Endif
				Endif
			Endif
		Endif
		Select (lcSel)
		Return lnGasit
	ENDPROC

	PROCEDURE inainte_de_do_termin
		*!* 14.08.2014
		*!* marius.mutu
		*!* S-a tratat cazul in care contul de TVA este 4428 (TVA incasare), nu numai 4426
		
		Local lcCursor, lcSel, lcSql, llAlegPartener, llRet, llVerificAnalitic, lnBazaLei, lnBazaVal
		Local lnNrActPrima, lcSerieActPrima, lnIdJtvaPrima, lnTaxCodePrima, lcLogSumar
		Local lnBazaVal2, lnNract, lnProcLei, lnProcVal, lnSucces, lnTvaLei, lnTvaVal, lnTvaVal2, loFact
		Local llRulTempPlin
		
		lnNract = 0
		
		llRet = .F.
		*!* fara sincronizare automata la Terminat - se salveaza exact ce vede utilizatorul;
		*!* daca o sincronizare armata (lSyncPending) nu a apucat sa ruleze, doar atentionam
		If Thisform.lSyncPending
			amessagebox("Exista modificari nesincronizate - apasati Recalculeaza (F5) si verificati nota!",0+48,"Atentie")
			Return .F.
		Endif
		If !Empty(Thisform.cmesajsync)
			amessagebox(Thisform.cmesajsync,0+48,"Atentie")
			Return .F.
		Endif
		lcSel = Thisform.grid1.RecordSource
		Select (lcSel)
		Locate For Empty(nract) And suma<>0
		If Found()
			amessagebox('Nu ati completat numarul actului!',0+48,"Atentie")
			Return m.llRet
		Endif
		
		*!*	modificare	v 2.1.42
		Go Top
		Locate For Empty(Nvl(id_fdoc,0)) And suma <> 0
		If Found()
			amessagebox("Nu ati completat tipul documentului!",0+48,"Atentie")
			Return m.llRet
		Endif
		*!*	modificare	v 2.1.42	^
		
		llVerificAnalitic = .T.
		llAlegPartener = .F.
		llRet = verificare_note_contabile(lcSel,llVerificAnalitic,llAlegPartener)
		
		If !m.llRet
			Return m.llRet
		Endif
		
		SELECT actactan 
		DELETE ALL 
		
		Thisform.nid_part_finalizarenir = 0	&&	modificare	v 2.1.39
		*!*	modificare  v 2.1.39 : am adaugat "or se_scrie = 1"
		Select introdc
		Scan For suma <> 0 Or se_scrie = 1
			Scatter Name loFact
			Select actactan
			Append Blank
			Gather Name poAct
			*!*	modificare	v 2.1.41 : am adaugat id_fdoc, fdoc, dataact
			Gather Name loFact Fields id_fdoc, fdoc, dataact, serie_Act,nract, partc, id_partc,partd, id_partd, suma, explicatia, explicatia4, explicatia5, scd, ascd, scc, ascc, ID_JTVA_coloana, taxcode, id_valuta, curs, nume_val
			Replace proc_tva With Round((loFact.ptva+100)/100,2)
			If loFact.in_valuta = 1
				Replace SUMA_val With loFact.SUMA_val
			Else
				Replace Curs With 0,id_valuta With 0, nume_val With ''
			Endif
		
			*!* 30.08.2007
			*!* MARIUS.MUTU
			*!* LAS NNIR DOAR PE PRIMA FACTURA (DE ACHIZITIE)
			*!* ALTFEL SE SCRIE IN RUL.NRACT ULTIMUL NUMAR DE DOCUMENT CU NNIR-UL RESPECTIV
			If nract <> 0 And lnNract <> nract And lnNract <> 0
				Replace nnir With 0
			Else
				lnNract = nract
			Endif
			*!*	modificare	v 2.1.39
			If Thisform.nid_part_finalizarenir = 0 And loFact.cu_tva = 0 And !Inlist(loFact.tip_rand,'D','G')
				Select actactan
				Append Blank
				Gather Name poAct
				Gather Name loFact Fields serie_Act, nract,  explicatia, explicatia4, explicatia5
				Replace scd With "", ascd With "", scc With "401", ascc With "",suma With 0,proc_tva With 0,id_jtva_coloana WITH Null
				loCauta = caut_partener([-2],[Alegeti furnizorul],,, .T.)
				If !Isnull(loCauta)
					Thisform.nid_part_finalizarenir = loCauta.id_part
					Select actactan
					Replace partc With loCauta.denumire,id_partc With loCauta.id_part
				Endif
			Endif
			*!*	modificare	v 2.1.39	^
			Select introdc
		Endscan
		
		*!* 30.08.2007
		*!* marius.mutu
		*!* calculez pretul in valuta incluzand si facturile in lei / curs care participa la pretul in valuta
		*!*	20.09.2012
		*!*	marius.atanasiu
		*!*		am scos conditia "cu_tva=1" de la toate SUM-urile de mai jos
		*!* sumarile si procentele se calculeaza in recalculeaza()
		Thisform.recalculeaza()
		lnBazaLei = Thisform.nbaza_lei
		lnBazaVal = Thisform.nbaza_val
		lnTvaLei = Thisform.ntva_lei
		lnTvaVal = Thisform.ntva_val
		lnProcLei = Thisform.procent_lei - Iif(Thisform.lIntern, 0, 100)
		lnProcVal = Thisform.procent_val
		
		Locate
		poAct.proc_tva = (100 + ptva)/100
		
		
		*!* rul_temp e creat in Load
		
		this.AlwaysOnTop = .F.
		*!* verificarea si scrierea NIR-ului, comune importului si achizitiei interne
		Select * From actactan Into Cursor crsActactanTemp READWRITE NOFILTER
		Do Form verificare With .T. , .T.
		If gnButon = 2
			Use In (Select('actactan'))
			Select * From crsActactanTemp Into Cursor actactan READWRITE NOFILTER
			Use In (Select('crsActactanTemp'))
			this.AlwaysOnTop = .T.
			Return .F.
		Endif
		Use In (Select('crsActactanTemp'))
		Select actactan
		Go Top
		lnNrActPrima = nract
		lcSerieActPrima = serie_act
		* completez TVA si TAXCODE cu datele de pe prima factura (ca in fluxul vechi)
		lnIdJtvaPrima = id_jtva_coloana
		lnTaxCodePrima = taxcode
		If Used('rul_temp')
			Select rul_temp
			Replace All nract With lnNrActPrima, serie_act With lcSerieActPrima, id_jtva_coloana With lnIdJtvaPrima, taxcode With lnTaxCodePrima
		Endif
		If Used('rul_temp_obinv')
			Select rul_temp_obinv
			Replace All nract With lnNrActPrima, serie_act With lcSerieActPrima
		Endif
		***** articolele negestionabile nu intra in rulaje/stoc (acelasi model ca la NIR normal)
		* le pastrez intr-un cursor temporar ca sa le pot readauga daca scrierea esueaza
		Select * From rul_temp Where Nvl(in_stoc,1) = 0 And !Deleted() Into Cursor crsNegest NOFILTER Readwrite
		Delete From rul_temp Where Nvl(in_stoc,1) = 0
		*!* sumar spargere in log, pentru reconstructie ulterioara
		If Type('goLog') = 'O'
			lcLogSumar = 'NIR import unificat: act ' + Alltrim(Nvl(lcSerieActPrima,'')) + ' ' + Alltrim(Str(Nvl(lnNrActPrima,0),14))
			Select introdc
			Scan For tip_rand = 'S' And !Deleted()
				lcLogSumar = lcLogSumar + ' | S ' + Alltrim(Nvl(scd,'')) + '=' + Alltrim(Str(Nvl(suma,0),14,2))
			Endscan
			Locate For tip_rand = 'D'
			If Found()
				lcLogSumar = lcLogSumar + ' | D ' + Alltrim(Nvl(scd,'')) + '=' + Alltrim(Str(Nvl(suma,0),14,2))
			Endif
			goLog.Log(lcLogSumar)
		Endif
		lnSucces = oscrie_in_fisiere(0,.F.,.T.)
		If lnSucces > 0
			Use In (Select('crsNegest'))
			Do listare_nir With poAct.nnir, gnTipGest In oproceduri_listari
			llRet = .T.
		Else
			* scrierea a esuat - readaug articolele negestionabile, ca grila sa ramana completa la reincercare
			Select rul_temp
			Append From Dbf('crsNegest')
			Use In (Select('crsNegest'))
			llRet = .F.
		Endif
		this.AlwaysOnTop = !llRet
		RETURN m.llRet
	ENDPROC

	PROCEDURE Init
		Lparameters tlIntern
		
		&& tlIntern - default formularul este folosit pentru import (.F.), daca este .T. atunci nu apar coloanele legate de valuta
		
		This.lIntern = Iif(Pcount() = 0 Or Type('tlIntern') <> 'L', .F., tlIntern)
		
		*!* rul_temp e creat in Load - inainte de instantierea membrilor, ca GridArt
		*!* (RecordSource = rul_temp) sa se lege de un cursor existent.
		
		This.lactiv4 = .T.	&& acces la do_sterge (butonul de stergere note)
		This.cDviSerie = ''
		This.cDviPartener = ''
		This.cDviFelDoc = ''
		
		If This.lIntern
			Select introdc
			Replace All suma_val With 0, in_valuta With 0
			Go Top	&&	modificare	v 2.1.37
			This.grid1.cInValuta.Visible = .F.
			This.grid1.cSumaVal.Visible = .F.
			This.grid1.cExplicatia5.Visible = .F.
			This.lb_titlu_alb_b121.Caption = "ACHIZIÞIE INTERNÃ MARFÃ/MATERIALE"
			*!* pe intern se ascund coloanele valutare de pe grila articolelor si importul XLS (cere pret in valuta)
			This.gridart.cPretFactura.ControlSource = "rul_temp.pret_lei"
			This.gridart.cPretFactura.Header1.Caption = "Pret lei factura"
			This.gridart.cPretFactura.InputMask = get_mask(10,gnPPret)
			This.gridart.cPretValutaCalculat.Visible = .F.
			This.gridart.cValoareValutaFactura.Visible = .F.
			This.gridart.cValoareValutaCalculat.Visible = .F.
			This.lblIncVal.Visible = .F.
			This.TxtIncVal.Visible = .F.
			This.lblDifVal.Visible = .F.
			This.TxtDifVal.Visible = .F.
			This.But_modiparam1.Visible = .F.
		*!*	 modificare v 2.1.40
		Else
		*!*	 modificare v 2.1.40	^
		Endif
		
		This.WindowState = 2
		
		this.grid1.HeaderHeight = 49 && se micsoreaza singur la afisare; refacut si in Show()
		*SAFT
		this.grid1.cTaxCode.Visible = m.gl406
		
		
		* Creez cursor cu Id-uri de TVA Taxare inversa si Comunitate Europeana pentru notele 4426 = 4426, la alegerea Explicatie TVA
		lcSql = "select ID_JTVA_COLOANA from JTVA_COLOANE t where (coloana_jc LIKE 'TI%T' or coloana_jc like 'XX%TIT') or (coloana_jc LIKE 'CE%T' and coloana_jc not LIKE 'CE%FTT') "
		lcCursor = 'cJtvaCol4427'
		llSucces = goExecutor.oExecuta(m.lcSql, lcCursor)
		IF m.llSucces
			SELECT cJtvaCol4427
			INDEX on ID_JTVA_COLOANA TAG ID_JTVA
		ENDIF 
		DoDefault()
		Thisform.refac_culori_documente()
		This._grdfooter1.attachToGrid(This.GridArt)
		This._grdfooter1.calcTotal()
		
	ENDPROC

	PROCEDURE KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl
		*!* F5 = sincronizare manuala
		If nKeyCode = -4
			Nodefault
			Thisform.sincronizeaza()
			Return
		Endif
		DoDefault(nKeyCode, nShiftAltCtrl)
	ENDPROC

	PROCEDURE Load
		*!* rul_temp trebuie sa existe inaintea instantierii membrilor: GridArt e legat de el
		*!* prin RecordSource, iar crearea lui dupa (in Init) lasa grila nelegata si goala.
		DoDefault()
		llRulTempPlin = .F.
		If Used('RUL_TEMP')
			llRulTempPlin = (Reccount('RUL_TEMP') > 0)
		Endif
		If !m.llRulTempPlin
			If Used('RUL_TEMP')
				Use In (Select('RUL_TEMP'))
			Endif
			lcSqlRul = [select r.*, r.pret as pret_lei, r.pretd as pret_val, 000.00 as cota_tva from ] + gcs + [.vrul r where 1=2 ]
			lnSuccesRul = goExecutor.oExecute(lcSqlRul,[rul_temp])
			If lnSuccesRul < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
				Return .F.
			Endif
		Endif
	ENDPROC

	PROCEDURE rand_protejat
		Return (Nvl(valuta_proprie,0) = 1)
	ENDPROC

	PROCEDURE recalculeaza
		*!* Totalurile formularului (baza si TVA, in lei si in valuta) si procentele de incarcare.
		*!* Baza unui document e Suma(S) daca a fost spart, altfel randul B - de aceea filtrul e
		*!* pe tip_rand IN ('B','S'). Pe import procent_lei = 100 (incarcarea in valuta se aplica
		*!* pe pretd, iar pretul in lei deriva din pretd*curs), iar documentele care nu participa
		*!* la pret raman pe randul D (recalc_diferente); pe intern procent_lei =
		*!* 100*baza_totala/baza_principala.
		Local lnBazaLei, lnBazaVal, lnBazaVal2, lnTvaLei, lnTvaVal, lnTvaVal2, lcSel
		Local lnMinNrDoc, lnBazaPrincipalaLei, lnBazaPrincipalaVal, lnDiscLei, lnDiscVal
		lcSel = Select()
		If !Used('introdc')
			Select (lcSel)
			Return
		Endif
		Select introdc
		If This.lIntern
			Sum suma For Inlist(tip_rand,'B','S') And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) And participa_valuta To lnBazaLei
			Sum suma For tip_rand = 'T' And !Empty(id_jtva_coloana) And participa_valuta To lnTvaLei
		Else
			Sum suma For Inlist(tip_rand,'B','S') And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) To lnBazaLei
			Sum suma For tip_rand = 'T' And !Empty(id_jtva_coloana) To lnTvaLei
		Endif
		Sum suma_val For Inlist(tip_rand,'B','S') And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) And in_valuta = 1 And Nvl(id_valuta,0) = Nvl(This.oact.id_valuta,0) And participa_valuta To lnBazaVal
		Sum Round(suma/This.oact.Curs, gnPval) For Inlist(tip_rand,'B','S') And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) And (in_valuta = 0 Or Nvl(id_valuta,0) <> Nvl(This.oact.id_valuta,0)) And participa_valuta To lnBazaVal2
		lnBazaVal = lnBazaVal + lnBazaVal2
		Sum suma_val For tip_rand = 'T' And !Empty(id_jtva_coloana) And in_valuta = 1 And Nvl(id_valuta,0) = Nvl(This.oact.id_valuta,0) And participa_valuta To lnTvaVal
		Sum Round(suma/This.oact.Curs, gnPval) For tip_rand = 'T' And !Empty(id_jtva_coloana) And (in_valuta = 0 Or Nvl(id_valuta,0) <> Nvl(This.oact.id_valuta,0)) And participa_valuta To lnTvaVal2
		lnTvaVal = lnTvaVal + lnTvaVal2
		
		*!* baza documentului principal (nr_doc minim dintre B/S), pentru procent_val, procent_lei (intern) si procentele pe rand
		lnMinNrDoc = 99999998
		Calculate Min(Iif(Inlist(tip_rand,'B','S'), nr_doc, 99999998)) To lnMinNrDoc
		Sum suma_val For Inlist(tip_rand,'B','S') And nr_doc = lnMinNrDoc And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) And in_valuta = 1 To lnBazaPrincipalaVal
		Sum suma For Inlist(tip_rand,'B','S') And nr_doc = lnMinNrDoc And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) To lnBazaPrincipalaLei
		Sum suma For tip_rand = 'G' To lnDiscLei
		Sum suma_val For tip_rand = 'G' To lnDiscVal
		
		This.nbaza_lei = lnBazaLei
		This.nbaza_val = lnBazaVal
		This.ntva_lei = lnTvaLei
		This.ntva_val = lnTvaVal
		This.ndisc_lei = lnDiscLei
		This.ndisc_val = lnDiscVal
		This.nbazaprincipala_lei = lnBazaPrincipalaLei
		This.nbazaprincipala_val = lnBazaPrincipalaVal
		If This.lIntern
			This.procent_lei = Iif(lnBazaPrincipalaLei <> 0, 100 * lnBazaLei / lnBazaPrincipalaLei, 100)
		Else
			*!* documentele fara participa_valuta nu incarca pretul - raman pe randul D
			This.procent_lei = 100
		Endif
		This.procent_val = Iif(lnBazaPrincipalaVal <> 0, 100 * lnBazaVal / lnBazaPrincipalaVal, 100)
		Select (lcSel)
	ENDPROC

	PROCEDURE recalc_diferente
		*!* Randul D, unic pe nota (doc_key gol, nr_doc 99999999): diferenta = baza documentelor
		*!* care participa la pret - Suma(pret*cant) cu pretul incarcat. Cont dominant = contul de
		*!* clasa 3 cu baza ABS maxima; fara clasa 3 -> clasa 2, cu contul fix 6588. Diferenta se
		*!* scrie doar in lei, fara TVA si fara cod de taxa SAFT. Antetul se mosteneste de la
		*!* documentul principal.
		Local lcSel, lnMinNrDoc, lnTotalLei, lnTotalVal, lnBazaParticipa
		Local lcContDominant, lnBazaDominantaAbs, lcScd1, lnDiferentaLei, lnDiferentaVal, lcExplicatie
		Local llGasitClasa3, loAntet
		lcSel = Select()
		
		If !Used('rul_temp') Or Reccount('rul_temp') = 0
			*!* fara articole nu exista diferenta - sterg randul D ramas orfan
			Select introdc
			Delete For tip_rand == 'D' And Nvl(mod_manual,0) <> 1
			Locate For tip_rand == 'D'
			This.ndif_lei = Iif(Found(), suma, 0)
			This.ndif_val = 0
			Select (lcSel)
			Return
		Endif
		
		Select introdc
		lnMinNrDoc = 99999998
		Calculate Min(Iif(Inlist(tip_rand,'B','S'), nr_doc, 99999998)) To lnMinNrDoc
		Locate For nr_doc = lnMinNrDoc And Inlist(tip_rand,'B','S')
		If !Found()
			Select (lcSel)
			Return
		Endif
		
		*!* randul D modificat manual (mod_manual=1) nu se rescrie/sterge, ca randurile T
		Locate For tip_rand == 'D'
		If Found() And Nvl(mod_manual,0) = 1
			This.ndif_lei = suma
			This.ndif_val = 0
			Select (lcSel)
			Return
		Endif
		
		Sum suma For Inlist(tip_rand,'B','S') And !Inlist(scd,'4426','4428') And !Empty(id_jtva_coloana) And participa_valuta To lnBazaParticipa
		
		Select Sum(Round(pret*cant,gnPc)) As tot_lei, Sum(Round(pretd*cant,gnPval)) As tot_val ;
			From rul_temp Where !Deleted() Into Cursor crsTotArt NOFILTER
		lnTotalLei = Nvl(crsTotArt.tot_lei, 0)
		lnTotalVal = Nvl(crsTotArt.tot_val, 0)
		Use In crsTotArt
		
		*!* contul dominant: clasa 3 cu baza (pret incarcat) ABS maxima;
		*!* fara clasa 3 -> clasa 2 (imobilizari), randul D cu cont fix 6588
		Select cont, Sum(Round(pret*cant,gnPc)) As baza_lei ;
			From rul_temp Where !Deleted() And Inlist(Left(Alltrim(Nvl(cont,'')),1),'2','3') Group By cont Into Cursor crsGrupDom NOFILTER
		lcContDominant = ''
		lnBazaDominantaAbs = -1
		Select crsGrupDom
		Scan For Left(Alltrim(cont),1) == '3'
			If Abs(baza_lei) > lnBazaDominantaAbs
				lnBazaDominantaAbs = Abs(baza_lei)
				lcContDominant = Alltrim(cont)
			Endif
			Select crsGrupDom
		Endscan
		llGasitClasa3 = !Empty(lcContDominant)
		If !llGasitClasa3
			Select crsGrupDom
			Scan
				If Abs(baza_lei) > lnBazaDominantaAbs
					lnBazaDominantaAbs = Abs(baza_lei)
					lcContDominant = Alltrim(cont)
				Endif
				Select crsGrupDom
			Endscan
		Endif
		Use In crsGrupDom
		
		lnDiferentaLei = Round(lnBazaParticipa - lnTotalLei, gnPc)
		This.ndif_lei = lnDiferentaLei
		This.ndif_val = 0
		
		If lnDiferentaLei = 0
			Select introdc
			Delete For tip_rand == 'D'
			Select (lcSel)
			Return
		Endif
		
		lcScd1 = ''
		If llGasitClasa3
			Do Case
			Case Left(lcContDominant,2) == '34'
				lcScd1 = '711'
			Case lcContDominant == '371'
				lcScd1 = '607'
			Case Inlist(lcContDominant, '381', '388')
				lcScd1 = '608'
			Otherwise
				lcScd1 = '60' + Substr(lcContDominant,3,2)
			Endcase
		Else
			lcScd1 = '6588'	&& dominant clasa 2 (imobilizari): alte cheltuieli de exploatare, fix
		Endif
		
		lcExplicatie = 'DIFERENTA'
		
		Select introdc
		Locate For tip_rand == 'D'
		If !Found()
			Locate For nr_doc = lnMinNrDoc And Inlist(tip_rand,'B','S')
			Scatter Name loAntet Memo
			Select introdc
			Append Blank
			Gather Name loAntet Memo
			Replace tip_rand With 'D', doc_key With '', nr_doc With 99999999, mod_manual With 0
			Replace partc With '', id_partc With 0, partd With '', id_partd With 0
		Endif
		Replace scd With lcScd1, scc With lcContDominant, suma With lnDiferentaLei, suma_val With 0, ;
			explicatia With lcExplicatie, id_jtva_coloana With Null, taxcode With 0, ptva With 0, cu_tva With 0, ;
			in_valuta With 0, participa_valuta With .F., nume_val With '', id_valuta With 0, curs With 0
		
		Select (lcSel)
	ENDPROC

	PROCEDURE recalc_tva_document
		*!* recalculeaza randurile T nemanuale (mod_manual<>1) ale documentului tcDocKey,
		*!* proportional cu bazele pe cota TVA (rul_temp) cand exista mai multe cote; nu
		*!* creeaza/sterge randuri T, nu atinge randurile T manuale.
		Lparameters tcDocKey
		Local lcSel, lnRec, llValuta, lnCurs, lnTotal, lnTotalVal, lnBazaTotala, lnPondere
		Local lnCntTSec, lnTotSLei2, lnPtvaSec, lnRestLei2, lnRestVal2, lnMaxAbs2, lnRecMaxAbs2
		lcSel = Select()
		lnRec = Recno('introdc')
		
		Select introdc
		Locate For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
		If !Found()
			Select (lcSel)
			If Between(lnRec, 1, Reccount('introdc'))
				Go lnRec In introdc
			Endif
			Return
		Endif
		
		Local loRandT
		Scatter Name loRandT Memo
		llValuta = (loRandT.in_valuta = 1)
		lnCurs = Iif(Nvl(loRandT.curs,0) <> 0, loRandT.curs, Thisform.oact.Curs)
		lnTotal = loRandT.suma_doc - Thisform.disc_document(tcDocKey, .F.)
		lnTotalVal = loRandT.suma_doc_val - Thisform.disc_document(tcDocKey, .T.)
		*!* bazele articolelor (rul_temp) descriu doar documentul principal (nr_doc minim intre B/S)
		Local lnMinNrDoc, llPrincipal
		lnMinNrDoc = 99999998
		Calculate Min(Iif(Inlist(tip_rand,'B','S'), nr_doc, 99999998)) To lnMinNrDoc
		llPrincipal = (loRandT.nr_doc = lnMinNrDoc)
		
		Local lnCntCote
		lnCntCote = 0
		If Used('rul_temp')
			*!* aceeasi grupare cota+creditor ca in sparge_document
			Thisform.calc_baze_cota_creditor(tcDocKey, loRandT)
			lnCntCote = Reccount('crsGrupCota')
		Endif
		
		If llPrincipal And lnCntCote > 1
			*!* principal cu mai multe cote/creditoare: bazele pe cota_tva+scc+ascc (rul_temp -> S), pondere = baza_grup / baza_totala
			If This.lIntern
				Select Sum(baza_lei) As tot From crsGrupCota Into Cursor crsBazaTot NOFILTER
			Else
				Select Sum(baza_val) As tot From crsGrupCota Into Cursor crsBazaTot NOFILTER
			Endif
			lnBazaTotala = Nvl(crsBazaTot.tot, 0)
			Use In crsBazaTot
			If lnBazaTotala = 0
				Use In crsGrupCota
				Select (lcSel)
				If Between(lnRec, 1, Reccount('introdc'))
					Go lnRec In introdc
				Endif
				Return
			Endif
		
			Select crsGrupCota
			Scan
				lnPondere = Iif(This.lIntern, baza_lei, baza_val) / lnBazaTotala
				Select introdc
				Scan For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 And ptva == crsGrupCota.cota_tva ;
					And Alltrim(Nvl(scc,'')) == Alltrim(Nvl(crsGrupCota.scc,'')) And Alltrim(Nvl(ascc,'')) == Alltrim(Nvl(crsGrupCota.ascc,''))
					If This.lIntern
						Replace suma With Round(lnTotal * lnPondere * ptva / 100, gnPc), suma_val With 0
					Else
						If llValuta
							Replace suma_val With Round(lnTotalVal * lnPondere * ptva / 100, gnPval)
							Replace suma With Round(suma_val * lnCurs, gnPc)
						Else
							*!* document secundar platit in lei: pondere aplicata direct pe suma_doc in lei
							Replace suma With Round(lnTotal * lnPondere * ptva / 100, gnPc), suma_val With 0
						Endif
					Endif
				Endscan
				Select crsGrupCota
			Endscan
			Use In crsGrupCota
		Else
			If Used('crsGrupCota')
				Use In crsGrupCota
			Endif
			*!* o singura cota / document secundar / fara rul_temp: T = total nou x ptva / 100;
			*!* daca T-urile secundarei sunt sparte pe creditori, fiecare primeste cota-parte
			*!* proportionala cu S-urile creditorului sau
			Select Count(*) As nr From introdc Where doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 Into Cursor crsCntTSec NOFILTER
			lnCntTSec = crsCntTSec.nr
			Use In crsCntTSec
			lnTotSLei2 = 0
			lnPtvaSec = 0
			If lnCntTSec > 1
				Select introdc
				Locate For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
				lnPtvaSec = ptva
				Select scc, ascc, Sum(suma) As s_lei From introdc ;
					Where doc_key == tcDocKey And tip_rand == 'S' ;
					Group By scc, ascc Into Cursor crsGrupSccR NOFILTER
				Select Sum(s_lei) As tot From crsGrupSccR Into Cursor crsTotSR NOFILTER
				lnTotSLei2 = Nvl(crsTotSR.tot,0)
				Use In crsTotSR
			Endif
			Select introdc
			Scan For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
				lnPondere = Iif(lnCntTSec > 1, 1 / lnCntTSec, 1)
				If lnCntTSec > 1 And lnTotSLei2 <> 0
					Select crsGrupSccR
					Locate For Alltrim(Nvl(scc,'')) == Alltrim(Nvl(introdc.scc,'')) And Alltrim(Nvl(ascc,'')) == Alltrim(Nvl(introdc.ascc,''))
					lnPondere = Iif(Found(), crsGrupSccR.s_lei / lnTotSLei2, 0)
					Select introdc
				Endif
				If This.lIntern
					Replace suma With Round(lnTotal * lnPondere * ptva / 100, gnPc), suma_val With 0
				Else
					If llValuta
						Replace suma_val With Round(lnTotalVal * lnPondere * ptva / 100, gnPval)
						Replace suma With Round(suma_val * lnCurs, gnPc)
					Else
						Replace suma With Round(lnTotal * lnPondere * ptva / 100, gnPc), suma_val With 0
					Endif
				Endif
			Select introdc
			Endscan
			If Used('crsGrupSccR')
				Use In crsGrupSccR
			Endif
			If lnCntTSec > 1
				*!* reziduul de rotunjire pe T-ul cu |suma| maxima
				Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
					Where doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 Into Cursor crsSumTSec2 NOFILTER
				If This.lIntern Or !llValuta
					lnRestLei2 = Round(lnTotal * lnPtvaSec / 100, gnPc) - Round(Nvl(crsSumTSec2.s_lei,0), gnPc)
					lnRestVal2 = 0
				Else
					lnRestVal2 = Round(lnTotalVal * lnPtvaSec / 100, gnPval) - Round(Nvl(crsSumTSec2.s_val,0), gnPval)
					lnRestLei2 = 0
				Endif
				Use In crsSumTSec2
				If lnRestLei2 <> 0 Or lnRestVal2 <> 0
					lnMaxAbs2 = -1
					lnRecMaxAbs2 = 0
					Select introdc
					Scan For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
						If Abs(suma) > lnMaxAbs2
							lnMaxAbs2 = Abs(suma)
							lnRecMaxAbs2 = Recno()
						Endif
					Endscan
					If lnRecMaxAbs2 > 0
						Go lnRecMaxAbs2 In introdc
						If lnRestVal2 <> 0
							Replace suma_val With suma_val + lnRestVal2
							Replace suma With Round(suma_val * lnCurs, gnPc)
						Else
							Replace suma With suma + lnRestLei2
						Endif
					Endif
				Endif
			Endif
		Endif
		
		Select (lcSel)
		If Between(lnRec, 1, Reccount('introdc'))
			Go lnRec In introdc
		Endif
	ENDPROC

	PROCEDURE refac_culori_documente
		* Culoare de fundal + eticheta document, precalculate pe cursorul introdc.
		* Cheia documentului e doc_key (calc_doc_key); primul rand B/S al unui doc_key defineste
		* documentul (B dispare dupa spargere), randul T mosteneste culoarea si eticheta.
		Local lcSel, lnDocCount, lnIdx, i, lcCheie, lnPrevColor, lcPrevLabel, lcPrevDocKey
		Local laCol[6], laKeys[100], lcDocKeyRec, lcTipRandRec
		If !Used('introdc')
			Return
		Endif
		laCol[1] = Rgb(221,235,247)
		laCol[2] = Rgb(226,239,218)
		laCol[3] = Rgb(255,242,204)
		laCol[4] = Rgb(237,225,247)
		laCol[5] = Rgb(252,228,214)
		laCol[6] = Rgb(255,221,221)
		lcSel = Select()
		Select introdc
		lcDocKeyRec = ''
		lcTipRandRec = ''
		If Reccount() > 0 And Between(Recno(), 1, Reccount())
			lcDocKeyRec = doc_key
			lcTipRandRec = tip_rand
		Endif
		lnDocCount = 0
		lnPrevColor = 16777215
		lcPrevLabel = '-'
		lcPrevDocKey = Chr(255)
		Go Top
		Scan
			Do Case
			Case Inlist(tip_rand, 'B', 'S') And !(doc_key == lcPrevDocKey)
				lcPrevDocKey = doc_key
				lcCheie = Thisform.calc_doc_key()
				If Empty(Alltrim(Nvl(serie_act,''))) And Nvl(nract,0) = 0
					Replace doc_color With 16777215, doc_label With '-'
				Else
					lnIdx = 0
					For i = 1 To lnDocCount
						If laKeys[i] == lcCheie
							lnIdx = i
							Exit
						Endif
					Endfor
					If lnIdx = 0 And lnDocCount < 100
						lnDocCount = lnDocCount + 1
						laKeys[lnDocCount] = lcCheie
						lnIdx = lnDocCount
					Endif
					If lnIdx = 0
						lnIdx = 1
					Endif
					Replace doc_color With laCol[Mod(lnIdx - 1, 6) + 1], doc_label With 'F' + Alltrim(Str(lnIdx))
				Endif
				lnPrevColor = doc_color
				lcPrevLabel = Alltrim(doc_label)
			Case Inlist(tip_rand, 'B', 'S')
				*!* S-urile urmatoare ale aceluiasi document
				Replace doc_color With lnPrevColor, doc_label With lcPrevLabel
			Case tip_rand == 'G'
				Replace doc_color With lnPrevColor, doc_label With Iif(lcPrevLabel == '-', '-', lcPrevLabel + ' DISC')
			Otherwise
				Replace doc_color With lnPrevColor, doc_label With Iif(lcPrevLabel == '-', '-', lcPrevLabel + ' TVA' + Iif(Thisform.rand_protejat(), '*', ''))
			Endcase
		Endscan
		Do Case
		Case lcTipRandRec == 'D'
			*!* randul D are doc_key gol - repozitionare dupa tip_rand
			Locate For tip_rand == 'D'
			If !Found()
				Go Top
			Endif
		Case !Empty(lcDocKeyRec)
			Locate For doc_key == lcDocKeyRec And tip_rand == lcTipRandRec
			If !Found()
				Go Top
			Endif
		Otherwise
			Go Top
		Endcase
		Select (lcSel)
	ENDPROC

	PROCEDURE Show
		Lparameters tnStyle
		*!* HeaderHeight se micsoreaza singur la afisare si taie liniile din capul
		*!* coloanelor - il refac la valoarea din design.
		If Pcount() = 0
			DoDefault()
		Else
			DoDefault(tnStyle)
		Endif
		This.grid1.HeaderHeight = 49
		*!* reface preturile articolelor la afisare, daca exista deja articole in rul_temp
		If Reccount('rul_temp') > 0
			This.do_reface()
		Endif
	ENDPROC

	PROCEDURE sincronizeaza
		*!* Orchestratorul sincronizarii; nu se apeleaza direct din Valid (eroare VFP 2166) - se
		*!* armeaza prin lSyncPending + tmrSync. lInSync e garda de reintrare.
		If This.lInSync
			Return
		Endif
		This.lInSync = .T.
		
		Local lcDocKeyPoz, lcTipRandPoz, lcScdPoz, lcDocKeyCrt, lnMinNrDocProc, lnValRandProc, ;
			lnMinNrDocGlobal, lcDocKeyBucla, lnNrDocDoc, llEsteParticipant
		lcDocKeyPoz = ''
		lcTipRandPoz = ''
		lcScdPoz = ''
		If Used('introdc') And Reccount('introdc') > 0 And Between(Recno('introdc'), 1, Reccount('introdc'))
			Select introdc
			lcDocKeyPoz = doc_key
			lcTipRandPoz = tip_rand
			lcScdPoz = scd
		Endif
		
		This.cmesajsync = ''
		
		*!* directia nota->articole: recalculez procentele, apoi do_reface reface preturile articolelor
		This.recalculeaza()
		If Pemstatus(This, 'do_reface', 5)
			This.do_reface()
		Endif
		
		*!* directia articole->nota: principala se sparge intotdeauna; secundarele doar daca
		*!* Thisform.lSpargeSecundare e activ si documentul chiar participa la pretul articolelor
		If Used('introdc')
			Select Distinct doc_key ;
				From introdc ;
				Where Inlist(tip_rand,'B','S') And !Empty(doc_key) ;
				Into Cursor crsDocs Nofilter
			Select introdc
			lnMinNrDocGlobal = 99999998
			Calculate Min(Iif(Inlist(tip_rand,'B','S'), nr_doc, 99999998)) To lnMinNrDocGlobal
			Select crsDocs
			Scan
				lcDocKeyBucla = crsDocs.doc_key
				Select introdc
				Locate For doc_key == lcDocKeyBucla And Inlist(tip_rand,'B','S')
				If !Found()
					Loop
				Endif
				lnNrDocDoc = nr_doc
				If lnNrDocDoc = lnMinNrDocGlobal
					Thisform.sparge_document(lcDocKeyBucla)
				Else
					llEsteParticipant = !Empty(id_jtva_coloana) And (!This.lIntern Or participa_valuta)
					If Thisform.lSpargeSecundare And llEsteParticipant
						Thisform.sparge_document(lcDocKeyBucla)
					Else
						Thisform.uneste_document(lcDocKeyBucla)
					Endif
				Endif
				Select crsDocs
			Endscan
			Use In crsDocs
		Endif
		
		This.recalc_diferente()
		
		*!* procente per rand (dupa spargere): raportate la baza documentului principal (nr_doc minim B/S).
		*!* NU se scriu in recalculeaza() - acolo ruleaza inaintea sparge_document(), deci S-urile
		*!* documentului principal inca nu exista la momentul respectiv.
		If Used('introdc') And Reccount('introdc') > 0
			Select introdc
			lnMinNrDocProc = 99999998
			Calculate Min(Iif(Inlist(tip_rand,'B','S'), nr_doc, 99999998)) To lnMinNrDocProc
			Scan For Inlist(tip_rand,'B','S')
				If nr_doc = lnMinNrDocProc
					Replace explicatia4 With '100.00'
					Replace explicatia5 With Iif(in_valuta = 1 Or participa_valuta, '100.00', '')
				Else
					If !This.lIntern And !participa_valuta
						Replace explicatia4 With ''
						Replace explicatia5 With ''
					Else
						Replace explicatia4 With Iif(This.nbazaprincipala_lei <> 0, Allt(Str(suma/This.nbazaprincipala_lei*100,6,2)), '')
						lnValRandProc = Iif(in_valuta = 1 And Nvl(id_valuta,0) = Nvl(This.oact.id_valuta,0), suma_val, Round(suma/This.oact.Curs, gnPval))
						Replace explicatia5 With Iif(This.nbazaprincipala_val <> 0, Allt(Str(lnValRandProc/This.nbazaprincipala_val*100,6,2)), '')
					Endif
				Endif
			Endscan
		Endif
		This.valideaza_sume()
		
		*!* restaurare pozitie (randul D dupa tip_rand - doc_key-ul lui e gol;
		*!* fallback: primul rand al documentului, apoi Go Top)
		Select introdc
		Do Case
		Case lcTipRandPoz == 'D'
			Locate For tip_rand == 'D'
			If !Found()
				Go Top
			Endif
		Case !Empty(lcDocKeyPoz)
			Locate For doc_key == lcDocKeyPoz And tip_rand == lcTipRandPoz And scd == lcScdPoz
			If !Found()
				Locate For doc_key == lcDocKeyPoz
			Endif
			If !Found()
				Go Top
			Endif
		Otherwise
			Go Top
		Endcase
		This.grid1.Refresh()
		
		This.refac_culori_documente()
		This.actualizeaza_banda()
		This.lInSync = .F.
	ENDPROC

	PROCEDURE sparge_discount
		*!* Sparge randurile G (discount) pe cotele TVA ale articolelor, proportional cu bazele pe
		*!* cota, pastrand totalul discountului. Cere crsGrupCota deschis (calc_baze_cota_creditor).
		Lparameters tcDocKey
		Local lcSel, lnCnt, lnTotLei, lnTotVal, lnBazaTot, lnPondere, lnCotaCrt, lnIdJtvaCrt
		Local lnRestLei, lnRestVal, lnMaxAbs, lnRecMaxAbs, loRandG
		lcSel = Select()
		
		Select introdc
		Locate For doc_key == tcDocKey And tip_rand == 'G'
		If !Found()
			Select (lcSel)
			Return
		Endif
		Scatter Name loRandG Memo
		Select Count(*) As nr, Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'G' Into Cursor crsTotG NOFILTER
		lnCnt = Nvl(crsTotG.nr, 0)
		lnTotLei = Nvl(crsTotG.s_lei, 0)
		lnTotVal = Nvl(crsTotG.s_val, 0)
		Use In crsTotG
		
		If This.lIntern
			Select cota_tva, Sum(baza_lei) As pond From crsGrupCota Group By cota_tva Into Cursor crsPondDisc NOFILTER
		Else
			Select cota_tva, Sum(baza_val) As pond From crsGrupCota Group By cota_tva Into Cursor crsPondDisc NOFILTER
		Endif
		Select Sum(pond) As tot From crsPondDisc Into Cursor crsPondDiscTot NOFILTER
		lnBazaTot = Nvl(crsPondDiscTot.tot, 0)
		Use In crsPondDiscTot
		Go Top In crsPondDisc
		If lnBazaTot = 0 Or (lnCnt = 1 And Reccount('crsPondDisc') = 1 And crsPondDisc.cota_tva = loRandG.ptva)
			*!* o singura cota, aceeasi cu a randului de discount - nimic de spart
			Use In crsPondDisc
			Select (lcSel)
			Return
		Endif
		
		Select introdc
		Delete For doc_key == tcDocKey And tip_rand == 'G'
		Select crsPondDisc
		Scan
			lnCotaCrt = crsPondDisc.cota_tva
			lnPondere = crsPondDisc.pond / lnBazaTot
			lnIdJtvaCrt = Iif(lnCotaCrt = loRandG.ptva, loRandG.id_jtva_coloana, Thisform.gaseste_jtva_cota(Nvl(loRandG.id_jtva_coloana,0), lnCotaCrt))
			Select introdc
			Append Blank
			Gather Name loRandG Memo
			Replace tip_rand With 'G', doc_key With tcDocKey, ptva With lnCotaCrt, ;
				suma With Round(lnTotLei * lnPondere, gnPc), suma_val With Round(lnTotVal * lnPondere, gnPval)
			If lnIdJtvaCrt <> 0
				Replace id_jtva_coloana With lnIdJtvaCrt
				Select jtva_coloane2
				Locate For id_jtva_coloana = lnIdJtvaCrt
				If Found()
					Replace explicatie_tva With jtva_coloane2.denumire In introdc
				Endif
			Endif
			Select crsPondDisc
		Endscan
		Use In crsPondDisc
		
		*!* reziduul de rotunjire pe randul de discount cu |suma| maxima
		Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'G' Into Cursor crsSumG NOFILTER
		lnRestLei = Round(lnTotLei - Nvl(crsSumG.s_lei,0), gnPc)
		lnRestVal = Round(lnTotVal - Nvl(crsSumG.s_val,0), gnPval)
		Use In crsSumG
		If lnRestLei <> 0 Or lnRestVal <> 0
			lnMaxAbs = -1
			lnRecMaxAbs = 0
			Select introdc
			Scan For doc_key == tcDocKey And tip_rand == 'G'
				If Abs(suma) > lnMaxAbs
					lnMaxAbs = Abs(suma)
					lnRecMaxAbs = Recno()
				Endif
			Endscan
			If lnRecMaxAbs > 0
				Go lnRecMaxAbs In introdc
				Replace suma With suma + lnRestLei, suma_val With suma_val + lnRestVal
			Endif
		Endif
		
		Select (lcSel)
	ENDPROC

	PROCEDURE sparge_document
		*!* Sparge documentul tcDocKey in randuri S, pe conturile articolelor din rul_temp.
		*!* Sablonul e randul B, sau primul S daca B a disparut la o spargere anterioara.
		*!* Totalul documentului se ia din suma_doc/suma_doc_val. Baza de repartizare e in moneda
		*!* documentului: import -> pret_val*cant, intern -> pret_lei*cant (suma_val = 0).
		*!* Fara articole S-urile dispar, iar B se recreeaza din primul S daca lipseste.
		Lparameters tcDocKey
		Local lcSel, lnAreArticole, llPrincipal, lnMinNrDoc, llValuta, lnCurs, llAreB, lnBazaArtTot
		Local loBaza, lnSumaDoc, lnSumaDocVal, lnRestLei, lnRestVal, lcContMaxAbs, lnMaxAbs, llAreManual, lnBazaTotala
		Local lnPondere, lnSumaS, lnSumaSVal, lnIdJtvaOrig, lnCotaCrt, lnIdJtvaCrt, lnRecMaxAbs
		Local loRandTS, lnTotTLei, lnTotTVal, lnTotSLei
		lcSel = Select()
		
		Select introdc
		Locate For doc_key == tcDocKey And tip_rand == 'B'
		llAreB = Found()
		If llAreB
			Scatter Name loBaza Memo
		Else
			Locate For doc_key == tcDocKey And tip_rand == 'S'
			If !Found()
				*!* documentul nu (mai) exista (nici B, nici S) - nimic de facut
				Select (lcSel)
				Return
			Endif
			Scatter Name loBaza Memo
		Endif
		If llAreB And Empty(Alltrim(Nvl(loBaza.scd_orig,'')))
			loBaza.scd_orig = Nvl(loBaza.scd,'')
			loBaza.ascd_orig = Nvl(loBaza.ascd,'')
		Endif
		lnSumaDoc = loBaza.suma_doc
		lnSumaDocVal = loBaza.suma_doc_val
		
		*!* documentul principal (cel cu articole) = nr_doc minim dintre B/S existente
		lnMinNrDoc = 99999998
		Calculate Min(Iif(Inlist(tip_rand,'B','S'), nr_doc, 99999998)) To lnMinNrDoc
		llPrincipal = (loBaza.nr_doc = lnMinNrDoc)
		
		lnAreArticole = 0
		If Used('rul_temp')
			Select Count(*) As nr From rul_temp Where !Deleted() Into Cursor crsCntArt NOFILTER
			lnAreArticole = crsCntArt.nr
			Use In crsCntArt
		Endif
		
		*!* articole fara cantitati/preturi (baza totala 0): documentele raman nesparte
		lnBazaArtTot = 0
		If lnAreArticole > 0
			If This.lIntern
				Select Sum(Round(pret_lei*cant,gnPc)) As tot From rul_temp Where !Deleted() Into Cursor crsBazaArtTot NOFILTER
			Else
				Select Sum(Round(pret_val*cant,gnPval)) As tot From rul_temp Where !Deleted() Into Cursor crsBazaArtTot NOFILTER
			Endif
			lnBazaArtTot = Nvl(crsBazaArtTot.tot, 0)
			Use In crsBazaArtTot
			If lnBazaArtTot = 0
				If !("Articolele nu au inca cantitati/preturi" $ Thisform.cmesajsync)
					Thisform.cmesajsync = Thisform.cmesajsync + Iif(Empty(Thisform.cmesajsync),'',Chr(13)+Chr(10)) + ;
						"Articolele nu au inca cantitati/preturi - completati-le; documentele raman nesincronizate."
				Endif
				Select (lcSel)
				Return
			Endif
		Endif
		
		llAreManual = .F.
		Select introdc
		Locate For doc_key == tcDocKey And Inlist(tip_rand,'S','D') And mod_manual = 1
		If Found()
			llAreManual = .T.
		Endif
		
		If lnAreArticole = 0
			*!* fara articole S-urile dispar neconditionat; B se recreeaza daca lipseste
			Select introdc
			Locate For doc_key == tcDocKey And tip_rand == 'S'
			If Found()
				If !llAreB
					Local loRandS, lcScdSablon
					Scatter Name loRandS Memo
					lcScdSablon = ''
					If Used('introdc_sablon')
						Select introdc_sablon
						Go 1
						lcScdSablon = scd
						Select introdc
					Endif
					Append Blank
					Gather Name loRandS Memo
					Replace tip_rand With 'B', doc_key With tcDocKey, scd With Iif(!Empty(Alltrim(Nvl(loRandS.scd_orig,''))), Alltrim(loRandS.scd_orig), lcScdSablon), ascd With Alltrim(Nvl(loRandS.ascd_orig,'')), ;
						suma With lnSumaDoc, suma_val With lnSumaDocVal, mod_manual With 0
				Endif
				Select introdc
				Delete For doc_key == tcDocKey And tip_rand == 'S'
			Endif
			Select (lcSel)
			Return
		Endif
		
		If llAreManual
			*!* editari manuale prezente - nu rescriu S-urile documentului
			Select (lcSel)
			Return
		Endif
		
		llValuta = (loBaza.in_valuta = 1)
		lnCurs = Iif(Nvl(loBaza.curs,0) <> 0, loBaza.curs, Thisform.oact.Curs)
		
		*!* partenerul debit completat pe S-uri se pastreaza la regenerare (per cont+analitic)
		Select scd, ascd, id_partd, partd From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'S' And Nvl(id_partd,0) <> 0 ;
			Into Cursor crsPartS NOFILTER
		
		*!* scc/ascc/id_partc/partc editate manual pe un S se pastreaza la regenerare
		*!* (se reaplica neconditionat mai jos, spre deosebire de crsPartS)
		Select scd, ascd, scc, ascc, id_partc, partc From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'S' And !Empty(Alltrim(Nvl(scc,''))) ;
			Into Cursor crsSccS NOFILTER
		
		*!* sterg S-urile existente ale documentului inainte de regenerare (altfel se
		*!* acumuleaza duplicate la fiecare resincronizare)
		Select introdc
		Delete For doc_key == tcDocKey And tip_rand == 'S'
		
		*!* articolele fara cota proprie preiau cota documentului, ca randurile S sa se poata grupa pe cota
		If llPrincipal And Nvl(loBaza.ptva,0) > 0
			Select rul_temp
			Replace cota_tva With loBaza.ptva For Nvl(cota_tva,0) <= 0
			Select introdc
		Endif
		
		*!* grupez articolele pe cont+analitic (la principal si pe cota TVA - randul S poarta cota
		*!* articolelor lui, in concordanta cu randul T al cotei), in moneda documentului
		If This.lIntern
			If llPrincipal
				Select cont, acont, cota_tva, Sum(Round(pret_lei*cant,gnPc)) As baza_lei, 0 As baza_val ;
					From rul_temp Where !Deleted() Group By cont, acont, cota_tva Into Cursor crsGrupCont NOFILTER
			Else
				Select cont, acont, 0 As cota_tva, Sum(Round(pret_lei*cant,gnPc)) As baza_lei, 0 As baza_val ;
					From rul_temp Where !Deleted() Group By cont, acont Into Cursor crsGrupCont NOFILTER
			Endif
		Else
			If llPrincipal
				Select cont, acont, cota_tva, Sum(Round(pret_val*cant,gnPval)) As baza_val, 0 As baza_lei ;
					From rul_temp Where !Deleted() Group By cont, acont, cota_tva Into Cursor crsGrupCont NOFILTER
			Else
				Select cont, acont, 0 As cota_tva, Sum(Round(pret_val*cant,gnPval)) As baza_val, 0 As baza_lei ;
					From rul_temp Where !Deleted() Group By cont, acont Into Cursor crsGrupCont NOFILTER
			Endif
		Endif
		
		If llPrincipal
			*!* factura principala: rand S per cont, la baza proprie a contului
			Select crsGrupCont
			Scan
				If This.lIntern
					Thisform.creeaza_rand_s(tcDocKey, cont, baza_lei, 0, loBaza, acont, cota_tva)
				Else
					Thisform.creeaza_rand_s(tcDocKey, cont, Round(baza_val*lnCurs,gnPc), Iif(loBaza.in_valuta = 1, baza_val, 0), loBaza, acont, cota_tva)
				Endif
				Select crsGrupCont
			Endscan
		Else
			*!* transport/taxe: proportional cu bazele articolelor per cont, raportat la baza totala
			*!* a facturii principale (in moneda documentului); debit = contul articolelor,
			*!* credit = mostenit din randul sablon (scc)
			If This.lIntern
				Select Sum(baza_lei) As tot From crsGrupCont Into Cursor crsBazaTotala NOFILTER
			Else
				Select Sum(baza_val) As tot From crsGrupCont Into Cursor crsBazaTotala NOFILTER
			Endif
			lnBazaTotala = Nvl(crsBazaTotala.tot, 0)
			Use In crsBazaTotala
			If lnBazaTotala = 0
				Use In crsGrupCont
				If Used('crsPartS')
					Use In crsPartS
				Endif
				Select (lcSel)
				Return
			Endif
			Select crsGrupCont
			Scan
				If This.lIntern
					lnPondere = baza_lei / lnBazaTotala
					lnSumaS = Round(lnSumaDoc * lnPondere, gnPc)
					lnSumaSVal = 0
				Else
					lnPondere = baza_val / lnBazaTotala
					If loBaza.in_valuta = 1
						lnSumaSVal = Round(lnSumaDocVal * lnPondere, gnPval)
						lnSumaS = Round(lnSumaSVal * lnCurs, gnPc)
					Else
						*!* document secundar platit in lei: se repartizeaza direct suma in lei
						lnSumaSVal = 0
						lnSumaS = Round(lnSumaDoc * lnPondere, gnPc)
					Endif
				Endif
				Thisform.creeaza_rand_s(tcDocKey, cont, lnSumaS, lnSumaSVal, loBaza, acont)
				Select crsGrupCont
			Endscan
		Endif
		Use In crsGrupCont
		
		*!* rotunjire independenta per moneda - reziduul pe randul S cu |suma| maxima,
		*!* raportat la suma_doc/suma_doc_val
		Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc Where doc_key == tcDocKey And tip_rand == 'S' Into Cursor crsSumS NOFILTER
		lnRestLei = Round(lnSumaDoc - Nvl(crsSumS.s_lei,0), gnPc)
		lnRestVal = Round(lnSumaDocVal - Nvl(crsSumS.s_val,0), gnPval)
		Use In crsSumS
		If lnRestLei <> 0
			lcContMaxAbs = ''
			lnMaxAbs = -1
			Select introdc
			Scan For doc_key == tcDocKey And tip_rand == 'S'
				If Abs(suma) > lnMaxAbs
					lnMaxAbs = Abs(suma)
					lcContMaxAbs = scd
				Endif
			Endscan
			Locate For doc_key == tcDocKey And tip_rand == 'S' And scd == lcContMaxAbs
			If Found()
				Replace suma With suma + lnRestLei
			Endif
		Endif
		If llValuta And lnRestVal <> 0
			lcContMaxAbs = ''
			lnMaxAbs = -1
			Select introdc
			Scan For doc_key == tcDocKey And tip_rand == 'S'
				If Abs(suma_val) > lnMaxAbs
					lnMaxAbs = Abs(suma_val)
					lcContMaxAbs = scd
				Endif
			Endscan
			Locate For doc_key == tcDocKey And tip_rand == 'S' And scd == lcContMaxAbs
			If Found()
				Replace suma_val With suma_val + lnRestVal
			Endif
		Endif
		
		If Used('crsPartS') And Reccount('crsPartS') > 0
			Select crsPartS
			Scan
				Select introdc
				Replace id_partd With crsPartS.id_partd, partd With crsPartS.partd ;
					For doc_key == tcDocKey And tip_rand == 'S' And Nvl(id_partd,0) = 0 ;
					And Alltrim(scd) == Alltrim(crsPartS.scd) And Alltrim(Nvl(ascd,'')) == Alltrim(Nvl(crsPartS.ascd,''))
				Select crsPartS
			Endscan
		Endif
		If Used('crsPartS')
			Use In crsPartS
		Endif
		
		*!* reaplic scc/ascc/id_partc/partc pe cheia scd+ascd - creditorul ales de utilizator
		*!* per cont invinge mostenirea din sablon
		If Used('crsSccS') And Reccount('crsSccS') > 0
			Select crsSccS
			Scan
				Select introdc
				Replace scc With crsSccS.scc, ascc With crsSccS.ascc, id_partc With crsSccS.id_partc, partc With crsSccS.partc ;
					For doc_key == tcDocKey And tip_rand == 'S' ;
					And Alltrim(scd) == Alltrim(crsSccS.scd) And Alltrim(Nvl(ascd,'')) == Alltrim(Nvl(crsSccS.ascd,''))
			Select crsSccS
			Endscan
		Endif
		If Used('crsSccS')
			Use In crsSccS
		Endif
		
		*!* explicatiile alese manual pe randuri T se pastreaza peste regenerare, pe cota
		Select ptva, id_jtva_coloana, explicatie_tva From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'T' And Nvl(expl_manual,0) = 1 ;
			Into Cursor crsExplT NOFILTER
		Select introdc
		
		*!* cate un rand T per cota TVA prezenta pe articolele documentului (doar la principal)
		If llPrincipal
			Select introdc
			Locate For doc_key == tcDocKey And tip_rand == 'T'
			If Found()
				Local loRandT, llTvaProtejat
				lnIdJtvaOrig = id_jtva_coloana
				llTvaProtejat = .F.
				Locate For doc_key == tcDocKey And tip_rand == 'T' And Nvl(valuta_proprie,0) <> 1
				If Found()
					Scatter Name loRandT Memo
				Else
					*!* TVA-ul documentului sta doar pe randul protejat (DVI cu valuta proprie) - se sparge
					*!* acela pe cotele articolelor, nu se nasc T-uri noi din randul de baza
					llTvaProtejat = .T.
					Locate For doc_key == tcDocKey And tip_rand == 'T' And Nvl(valuta_proprie,0) = 1
					Scatter Name loRandT Memo
				Endif
				Select rul_temp
				Replace cota_tva With loRandT.ptva For Nvl(cota_tva,0) <= 0
				*!* grupare pe cota + creditor (scc/ascc) al S-ului corespunzator contului articolului
				Thisform.calc_baze_cota_creditor(tcDocKey, loBaza)
				Local lnBazaGrupTot, lnFactorDisc
				If This.lIntern
					Select Sum(baza_lei) As tot From crsGrupCota Into Cursor crsBazaGrupTot NOFILTER
					lnBazaGrupTot = Nvl(crsBazaGrupTot.tot, 0)
					Use In crsBazaGrupTot
					lnFactorDisc = Iif(lnBazaGrupTot <> 0, Max((lnBazaGrupTot - Thisform.disc_document(tcDocKey, .F.)) / lnBazaGrupTot, 0), 1)
				Else
					Select Sum(baza_val) As tot From crsGrupCota Into Cursor crsBazaGrupTot NOFILTER
					lnBazaGrupTot = Nvl(crsBazaGrupTot.tot, 0)
					Use In crsBazaGrupTot
					lnFactorDisc = Iif(lnBazaGrupTot <> 0, Max((lnBazaGrupTot - Thisform.disc_document(tcDocKey, .T.)) / lnBazaGrupTot, 0), 1)
				Endif
				If Reccount('crsGrupCota') > 0
					Thisform.sparge_discount(tcDocKey)
				Endif
				If llTvaProtejat And Reccount('crsGrupCota') > 0
					Thisform.sparge_tva_protejat(tcDocKey, loRandT, lnIdJtvaOrig)
				Endif
				If Reccount('crsGrupCota') > 0 And !llTvaProtejat
					Select introdc
					*!* T-urile manuale (mod_manual=1) nu se sterg - raman neatinse
					Delete For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
					Select crsGrupCota
					Scan
						lnCotaCrt = cota_tva
						*!* cota are deja un rand T manual - nu se recreaza (evita duplicat)
						Select introdc
						Locate For doc_key == tcDocKey And tip_rand == 'T' And ptva == lnCotaCrt And mod_manual = 1 ;
							And Alltrim(Nvl(scc,'')) == Alltrim(Nvl(crsGrupCota.scc,'')) And Alltrim(Nvl(ascc,'')) == Alltrim(Nvl(crsGrupCota.ascc,''))
						If Found()
							Select crsGrupCota
							Loop
						Endif
						If lnCotaCrt = loRandT.ptva
							lnIdJtvaCrt = lnIdJtvaOrig
						Else
							lnIdJtvaCrt = Thisform.gaseste_jtva_cota(lnIdJtvaOrig, lnCotaCrt)
						Endif
						If lnIdJtvaCrt = 0
							Thisform.cmesajsync = Thisform.cmesajsync + Iif(Empty(Thisform.cmesajsync),'',Chr(13)+Chr(10)) + ;
								"Documentul " + Alltrim(Nvl(loRandT.fdoc,'')) + " are marfa la " + Transform(lnCotaCrt) + "%, dar nu exista explicatie TVA de " + Transform(lnCotaCrt) + "% in seria '" + Alltrim(Strtran(Chrtran(Nvl(loRandT.explicatie_tva,''),'0123456789%',''),'  ',' ')) + "' - completati nomenclatorul de explicatii TVA."
						Else
							Select introdc
							Append Blank
							Gather Name loRandT Memo
							Replace rand_dvi With 0, valuta_proprie With 0, expl_manual With 0
							If This.lIntern
								Replace tip_rand With 'T', doc_key With tcDocKey, nr_doc With loRandT.nr_doc, ;
									id_jtva_coloana With lnIdJtvaCrt, ptva With lnCotaCrt, ;
									scc With crsGrupCota.scc, ascc With crsGrupCota.ascc, ;
									suma With Round(crsGrupCota.baza_lei * lnFactorDisc * lnCotaCrt / 100, gnPc), suma_val With 0
							Else
								Replace tip_rand With 'T', doc_key With tcDocKey, nr_doc With loRandT.nr_doc, ;
									id_jtva_coloana With lnIdJtvaCrt, ptva With lnCotaCrt, ;
									scc With crsGrupCota.scc, ascc With crsGrupCota.ascc, ;
									suma_val With Round(crsGrupCota.baza_val * lnFactorDisc * lnCotaCrt / 100, gnPval)
								Replace suma With Round(suma_val * lnCurs, gnPc)
								If !llValuta
									Replace suma_val With 0
								Endif
							Endif
							If lnIdJtvaCrt <> lnIdJtvaOrig
								Select jtva_coloane2
								Locate For id_jtva_coloana = lnIdJtvaCrt
								If Found()
									Select introdc
									Replace explicatie_tva With jtva_coloane2.denumire
								Endif
								Select introdc
								Thisform.UpdateExplicatieSAFT()
							Endif
						Endif
						Select crsGrupCota
					Endscan
		
					*!* rotunjire reziduala per cota: suma T-urilor nemanuale ale unei cote trebuie sa fie
					*!* exact baza_cota*cota/100, reziduul merge pe T-ul cu |suma| maxima al cotei.
					*!* Cotele care au deja un T manual se sar.
					Select Distinct cota_tva From crsGrupCota Into Cursor crsCoteRund NOFILTER
					Select crsCoteRund
					Scan
						lnCotaCrt = crsCoteRund.cota_tva
						Select introdc
						Locate For doc_key == tcDocKey And tip_rand == 'T' And ptva == lnCotaCrt And mod_manual = 1
						If !Found()
							Select Sum(baza_lei) As tot_lei, Sum(baza_val) As tot_val, Count(*) As nr_grup ;
								From crsGrupCota Where cota_tva == lnCotaCrt Into Cursor crsBazaCota NOFILTER
							If crsBazaCota.nr_grup > 1
								If This.lIntern Or !llValuta
									Select Sum(suma) As s From introdc Where doc_key == tcDocKey And tip_rand == 'T' And ptva == lnCotaCrt And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 Into Cursor crsSumTCota NOFILTER
									If This.lIntern
										lnRestLei = Round(crsBazaCota.tot_lei * lnFactorDisc * lnCotaCrt / 100, gnPc) - Round(Nvl(crsSumTCota.s,0), gnPc)
									Else
										lnRestLei = Round(Round(crsBazaCota.tot_val * lnFactorDisc * lnCotaCrt / 100, gnPval) * lnCurs, gnPc) - Round(Nvl(crsSumTCota.s,0), gnPc)
									Endif
									Use In crsSumTCota
									If lnRestLei <> 0
										lnMaxAbs = -1
										lnRecMaxAbs = 0
										Select introdc
										Scan For doc_key == tcDocKey And tip_rand == 'T' And ptva == lnCotaCrt And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
											If Abs(suma) > lnMaxAbs
												lnMaxAbs = Abs(suma)
												lnRecMaxAbs = Recno()
											Endif
										Endscan
										If lnRecMaxAbs > 0
											Go lnRecMaxAbs In introdc
											Replace suma With suma + lnRestLei
										Endif
									Endif
								Else
									Select Sum(suma_val) As s From introdc Where doc_key == tcDocKey And tip_rand == 'T' And ptva == lnCotaCrt And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 Into Cursor crsSumTCota NOFILTER
									lnRestVal = Round(crsBazaCota.tot_val * lnFactorDisc * lnCotaCrt / 100, gnPval) - Round(Nvl(crsSumTCota.s,0), gnPval)
									Use In crsSumTCota
									If lnRestVal <> 0
										lnMaxAbs = -1
										lnRecMaxAbs = 0
										Select introdc
										Scan For doc_key == tcDocKey And tip_rand == 'T' And ptva == lnCotaCrt And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
											If Abs(suma_val) > lnMaxAbs
												lnMaxAbs = Abs(suma_val)
												lnRecMaxAbs = Recno()
											Endif
										Endscan
										If lnRecMaxAbs > 0
											Go lnRecMaxAbs In introdc
											Replace suma_val With suma_val + lnRestVal
											Replace suma With Round(suma_val * lnCurs, gnPc)
										Endif
									Endif
								Endif
							Endif
							Use In crsBazaCota
						Endif
						Select crsCoteRund
					Endscan
					Use In crsCoteRund
				Endif
				Use In crsGrupCota
			Endif
		Endif
		
		If !llPrincipal
			*!* secundara: T-urile nemanuale se regrupeaza pe creditorii S-urilor (scc/ascc),
			*!* impartind totalul T existent proportional cu sumele S per creditor
			Select introdc
			Locate For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
			If Found()
				Scatter Name loRandTS Memo
				Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
					Where doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 Into Cursor crsTotTSec NOFILTER
				lnTotTLei = Nvl(crsTotTSec.s_lei,0)
				lnTotTVal = Nvl(crsTotTSec.s_val,0)
				Use In crsTotTSec
				Select scc, ascc, Sum(suma) As s_lei From introdc ;
					Where doc_key == tcDocKey And tip_rand == 'S' ;
					Group By scc, ascc Into Cursor crsGrupSccT NOFILTER
				Select Sum(s_lei) As tot From crsGrupSccT Into Cursor crsTotSSec NOFILTER
				lnTotSLei = Nvl(crsTotSSec.tot,0)
				Use In crsTotSSec
				If Reccount('crsGrupSccT') > 0 And lnTotSLei <> 0
					Select introdc
					Delete For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
					Select crsGrupSccT
					Scan
						lnPondere = crsGrupSccT.s_lei / lnTotSLei
						Select introdc
						Append Blank
						Gather Name loRandTS Memo
						Replace rand_dvi With 0, valuta_proprie With 0, expl_manual With 0
						Replace scc With crsGrupSccT.scc, ascc With crsGrupSccT.ascc, ;
							suma With Round(lnTotTLei * lnPondere, gnPc), ;
							suma_val With Round(lnTotTVal * lnPondere, gnPval)
						Select crsGrupSccT
					Endscan
					*!* reziduul de rotunjire pe T-ul cu |suma| maxima
					Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
						Where doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 Into Cursor crsSumTSec NOFILTER
					lnRestLei = Round(lnTotTLei - Nvl(crsSumTSec.s_lei,0), gnPc)
					lnRestVal = Round(lnTotTVal - Nvl(crsSumTSec.s_val,0), gnPval)
					Use In crsSumTSec
					If lnRestLei <> 0 Or lnRestVal <> 0
						lnMaxAbs = -1
						lnRecMaxAbs = 0
						Select introdc
						Scan For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
							If Abs(suma) > lnMaxAbs
								lnMaxAbs = Abs(suma)
								lnRecMaxAbs = Recno()
							Endif
						Endscan
						If lnRecMaxAbs > 0
							Go lnRecMaxAbs In introdc
							Replace suma With suma + lnRestLei, suma_val With suma_val + lnRestVal
						Endif
					Endif
				Endif
				Use In crsGrupSccT
			Endif
		Endif
		
		*!* explicatiile alese manual pe randuri T revin pe cota lor, restul urmeaza familia S-ului
		Select crsExplT
		Scan
			Select introdc
			Replace id_jtva_coloana With crsExplT.id_jtva_coloana, explicatie_tva With crsExplT.explicatie_tva, expl_manual With 1 ;
				For doc_key == tcDocKey And tip_rand == 'T' And ptva == crsExplT.ptva
			Select crsExplT
		Endscan
		Use In crsExplT
		Thisform.aliniaza_tva_la_baza(tcDocKey)
		
		*!* randul B dispare dupa spargere
		Select introdc
		Delete For doc_key == tcDocKey And tip_rand == 'B'
		
		Select (lcSel)
	ENDPROC

	PROCEDURE sparge_tva_protejat
		*!* Sparge randurile T protejate (TVA pe DVI cu valuta proprie) pe cotele TVA ale
		*!* articolelor, pastrand totalul introdus pe DVI, identitatea vamala si protectia.
		*!* Cere crsGrupCota deschis (calc_baze_cota_creditor).
		Lparameters tcDocKey, toRandT, tnIdJtvaOrig
		Local lcSel, lnTotLei, lnTotVal, lnCntProt, lnPonderiTot, lnPondere, lnCotaCrt, lnIdJtvaCrt
		Local lnRestLei, lnRestVal, lnMaxAbs, lnRecMaxAbs
		lcSel = Select()
		
		Select Count(*) As nr, Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'T' And Nvl(valuta_proprie,0) = 1 Into Cursor crsTotTProt NOFILTER
		lnCntProt = Nvl(crsTotTProt.nr, 0)
		lnTotLei = Nvl(crsTotTProt.s_lei, 0)
		lnTotVal = Nvl(crsTotTProt.s_val, 0)
		Use In crsTotTProt
		
		*!* ponderea unei cote = baza articolelor pe cota x cota (in moneda documentului)
		If This.lIntern
			Select cota_tva, Sum(Round(baza_lei * cota_tva / 100, gnPc)) As pond ;
				From crsGrupCota Group By cota_tva Into Cursor crsPondCota NOFILTER
		Else
			Select cota_tva, Sum(Round(baza_val * cota_tva / 100, gnPval)) As pond ;
				From crsGrupCota Group By cota_tva Into Cursor crsPondCota NOFILTER
		Endif
		Select Sum(pond) As tot From crsPondCota Into Cursor crsPondTot NOFILTER
		lnPonderiTot = Nvl(crsPondTot.tot, 0)
		Use In crsPondTot
		Go Top In crsPondCota
		If lnPonderiTot = 0 Or (lnCntProt = 1 And Reccount('crsPondCota') = 1 And crsPondCota.cota_tva = toRandT.ptva)
			*!* nimic de spart: o singura cota, aceeasi cu a randului protejat
			Use In crsPondCota
			Select (lcSel)
			Return
		Endif
		
		*!* creditorul fiecarei cote se pastreaza peste recreare - clonarea lui toRandT ar da
		*!* tuturor cotelor creditorul primului rand protejat
		Select ptva, scc, ascc From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'T' And Nvl(valuta_proprie,0) = 1 ;
			Into Cursor crsSccProt NOFILTER
		Select introdc
		Delete For doc_key == tcDocKey And tip_rand == 'T' And Nvl(valuta_proprie,0) = 1
		Select crsPondCota
		Scan
			lnCotaCrt = crsPondCota.cota_tva
			lnPondere = crsPondCota.pond / lnPonderiTot
			lnIdJtvaCrt = Iif(lnCotaCrt = toRandT.ptva, tnIdJtvaOrig, Thisform.gaseste_jtva_cota(tnIdJtvaOrig, lnCotaCrt))
			Select introdc
			Append Blank
			Gather Name toRandT Memo
			Replace tip_rand With 'T', doc_key With tcDocKey, nr_doc With toRandT.nr_doc, ptva With lnCotaCrt, ;
				suma With Round(lnTotLei * lnPondere, gnPc), suma_val With Round(lnTotVal * lnPondere, gnPval), ;
				expl_manual With Iif(lnCotaCrt = toRandT.ptva, Nvl(toRandT.expl_manual,0), 0)
			Select crsSccProt
			Locate For ptva = lnCotaCrt
			If Found()
				Replace scc With crsSccProt.scc, ascc With Nvl(crsSccProt.ascc,'') In introdc
			Endif
			Select introdc
			If lnIdJtvaCrt = 0
				Thisform.cmesajsync = Thisform.cmesajsync + Iif(Empty(Thisform.cmesajsync),'',Chr(13)+Chr(10)) + ;
					"Documentul " + Alltrim(Nvl(toRandT.fdoc,'')) + " are marfa la " + Transform(lnCotaCrt) + "%, dar nu exista explicatie TVA de " + Transform(lnCotaCrt) + "% in seria '" + Alltrim(Strtran(Chrtran(Nvl(toRandT.explicatie_tva,''),'0123456789%',''),'  ',' ')) + "' - completati nomenclatorul de explicatii TVA."
			Else
				Replace id_jtva_coloana With lnIdJtvaCrt
				If lnIdJtvaCrt <> tnIdJtvaOrig
					Select jtva_coloane2
					Locate For id_jtva_coloana = lnIdJtvaCrt
					If Found()
						Select introdc
						Replace explicatie_tva With jtva_coloane2.denumire
					Endif
					Select introdc
					Thisform.UpdateExplicatieSAFT()
				Endif
			Endif
			Select crsPondCota
		Endscan
		Use In crsPondCota
		Use In crsSccProt
		
		*!* reziduul de rotunjire pe randul cu |suma| maxima
		Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'T' And Nvl(valuta_proprie,0) = 1 Into Cursor crsSumTProt NOFILTER
		lnRestLei = Round(lnTotLei - Nvl(crsSumTProt.s_lei,0), gnPc)
		lnRestVal = Round(lnTotVal - Nvl(crsSumTProt.s_val,0), gnPval)
		Use In crsSumTProt
		If lnRestLei <> 0 Or lnRestVal <> 0
			lnMaxAbs = -1
			lnRecMaxAbs = 0
			Select introdc
			Scan For doc_key == tcDocKey And tip_rand == 'T' And Nvl(valuta_proprie,0) = 1
				If Abs(suma) > lnMaxAbs
					lnMaxAbs = Abs(suma)
					lnRecMaxAbs = Recno()
				Endif
			Endscan
			If lnRecMaxAbs > 0
				Go lnRecMaxAbs In introdc
				Replace suma With suma + lnRestLei, suma_val With suma_val + lnRestVal
			Endif
		Endif
		
		Select (lcSel)
	ENDPROC

	PROCEDURE uneste_document
		*!* reface randul B al unui document din S-urile lui (cand spargerea secundarelor e oprita)
		Lparameters tcDocKey
		Local lcSel, lcScdB, lcAscdB, lnMaxAbs
		Local lnCntTU, lnSumTULei, lnSumTUVal, lnRecTU
		lcSel = Select()
		Select introdc
		Locate For doc_key == tcDocKey And tip_rand == 'S'
		If !Found()
			Select (lcSel)
			Return
		Endif
		*!* editari manuale prezente - nu ating documentul
		Locate For doc_key == tcDocKey And Inlist(tip_rand,'S','D') And mod_manual = 1
		If Found()
			Select (lcSel)
			Return
		Endif
		Local loS
		Locate For doc_key == tcDocKey And tip_rand == 'S'
		Scatter Name loS Memo
		*!* contul B: cel original (scd_orig) daca exista, altfel al S-ului cu |suma| maxima
		lcScdB = Alltrim(Nvl(loS.scd_orig,''))
		lcAscdB = Alltrim(Nvl(loS.ascd_orig,''))
		If Empty(lcScdB)
			lnMaxAbs = -1
			Scan For doc_key == tcDocKey And tip_rand == 'S'
				If Abs(suma) > lnMaxAbs
					lnMaxAbs = Abs(suma)
					lcScdB = Alltrim(scd)
					lcAscdB = Alltrim(Nvl(ascd,''))
				Endif
			Endscan
		Endif
		Append Blank
		Gather Name loS Memo
		Replace tip_rand With 'B', doc_key With tcDocKey, scd With lcScdB, ascd With lcAscdB, ;
			suma With loS.suma_doc, suma_val With loS.suma_doc_val, mod_manual With 0
		Delete For doc_key == tcDocKey And tip_rand == 'S'
		*!* T-urile nemanuale sparte pe creditori se reunesc intr-unul singur (documentul revine la B unic)
		Select Count(*) As nr, Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc ;
			Where doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 Into Cursor crsTU NOFILTER
		lnCntTU = crsTU.nr
		lnSumTULei = Nvl(crsTU.s_lei,0)
		lnSumTUVal = Nvl(crsTU.s_val,0)
		Use In crsTU
		If lnCntTU > 1
			Select introdc
			Locate For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1
			lnRecTU = Recno()
			Delete For doc_key == tcDocKey And tip_rand == 'T' And mod_manual <> 1 And Nvl(valuta_proprie,0) <> 1 And Recno() <> lnRecTU
			Go lnRecTU In introdc
			Replace suma With lnSumTULei, suma_val With lnSumTUVal
		Endif
		Select (lcSel)
	ENDPROC

	PROCEDURE updateexplicatiesaft
		* Daca nu este activata SAFT 406 nu fac nimic
		IF !m.gl406
			RETURN
		ENDIF
		
		Local loPartenerRTVAI As "empty"
		Local loPartenerRTVAIX As "empty"
		Local lcCodFiscal, lcNumePart, ldDataAct, llFurnizorRTVAI, lnIdJtva, lnIdPart, lnTaxCode, lcSelect
		
		lcSelect = SELECT()
		
		
		ldDataAct = poAct.dataact
		lnIdJtva = introdc.id_jtva_coloana
		llFurnizorRTVAI = .F.
		lnIdPart = Nvl(introdc.id_partc, introdc.id_partd)
		
		lnTaxCode = GetTaxCodeIdPart(m.gnAn, m.gnLuna, m.ldDataAct, m.lnIdJtva, m.lnIdPart)
		Replace taxcode With m.lnTaxCode In introdc
		*This.grid1.cTaxCode._combobox1.Refresh()
		
		SELECT (m.lcSelect)
	ENDPROC

	PROCEDURE valideaza_sume
		*!* Verifica Suma(S) fata de suma_doc per document si articolele fara cont; cmesajsync
		*!* acumuleaza si mesajele setate de sparge_document/recalc_diferente.
		*!* Return .F. daca exista vreun mesaj.
		Local lcSel, lcMesaje, lcDocKeyCrt, lnSumaS, lnSumaDoc, lnSumaSVal, lnSumaDocVal, lcSelAna, lnSuccesAna, lcArtMesaj, lcContCrt, lcAcontCrt, lcDenCrt, lcMsgCrt, lcConturiAna
		lcSel = Select()
		lcMesaje = Thisform.cmesajsync
		
		If Used('introdc')
			Select Distinct doc_key From introdc Where tip_rand == 'S' Into Cursor crsDocSparte NOFILTER
			Select crsDocSparte
			Scan
				lcDocKeyCrt = doc_key
				Select introdc
				Locate For doc_key == lcDocKeyCrt And tip_rand == 'S'
				lnSumaDoc = suma_doc
				lnSumaDocVal = suma_doc_val
				Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc Where doc_key == lcDocKeyCrt And tip_rand == 'S' Into Cursor crsSumS NOFILTER
				lnSumaS = Nvl(crsSumS.s_lei,0)
				lnSumaSVal = Nvl(crsSumS.s_val,0)
				Use In crsSumS
				If Round(lnSumaS - lnSumaDoc, gnPc) <> 0 Or Round(lnSumaSVal - lnSumaDocVal, gnPval) <> 0
					*!* pe documente in valuta, mesajul in moneda documentului (sumele in lei nu apar in grila)
					If introdc.in_valuta = 1
						lcMesaje = lcMesaje + Iif(Empty(lcMesaje),'',Chr(13)+Chr(10)) + ;
							"Document " + Alltrim(Nvl(introdc.fdoc,'')) + " " + Alltrim(Nvl(introdc.serie_act,'')) + Transform(introdc.nract) + ;
							": suma subrandurilor (" + Transform(lnSumaSVal) + " " + Alltrim(Nvl(introdc.nume_val,'')) + " / " + Transform(lnSumaS) + " lei)" + ;
							" difera de suma facturii (" + Transform(lnSumaDocVal) + " " + Alltrim(Nvl(introdc.nume_val,'')) + " / " + Transform(lnSumaDoc) + " lei)."
					Else
						lcMesaje = lcMesaje + Iif(Empty(lcMesaje),'',Chr(13)+Chr(10)) + ;
							"Document " + Alltrim(Nvl(introdc.fdoc,'')) + " " + Alltrim(Nvl(introdc.serie_act,'')) + Transform(introdc.nract) + ;
							": suma subrandurilor (" + Transform(lnSumaS) + ") difera de suma facturii (" + Transform(lnSumaDoc) + ")."
					Endif
				Endif
				Select crsDocSparte
			Endscan
			Use In crsDocSparte
		Endif
		
		*!* articol fara cont in nomenclator
		If Used('rul_temp')
			Select Count(*) As nr From rul_temp Where !Deleted() And Empty(Alltrim(Nvl(cont,''))) Into Cursor crsFaraCont NOFILTER
			If crsFaraCont.nr > 0
				lcMesaje = lcMesaje + Iif(Empty(lcMesaje),'',Chr(13)+Chr(10)) + ;
					Transform(crsFaraCont.nr) + " articol(e) fara cont in nomenclator."
			Endif
			Use In crsFaraCont
		Endif
		
		*!* cont de articol cu analitice in plan, neasignat sau necunoscut (vezi assign_analitic)
		If Used('rul_temp') And Reccount('rul_temp') > 0
			lcConturiAna = cursor2listac('rul_temp','cont',',',[!Deleted() And !Empty(Alltrim(Nvl(cont,'')))])
			If !Empty(lcConturiAna)
				lcSelAna = [select cont, acont from ] + gcS + [.vplcont_analitic where inactiv = 0 and an = ?gnAn and acont is not null and rtrim(cont) in (] + lcConturiAna + [) order by cont]
				lnSuccesAna = goExecutor.oExecute(lcSelAna,'crsPlanAna')
				If lnSuccesAna < 0
					lcMesaje = lcMesaje + Iif(Empty(lcMesaje),'',Chr(13)+Chr(10)) + ;
						"Eroare verificare analitic articole: " + goExecutor.cEroare
				Else
					If lnSuccesAna > 0
						lcArtMesaj = ''
						Select rul_temp
						Scan For !Deleted() And !Empty(Alltrim(Nvl(cont,'')))
							lcContCrt = Alltrim(cont)
							lcAcontCrt = Alltrim(Nvl(acont,''))
							lcDenCrt = Alltrim(Nvl(denumire,''))
							Select crsPlanAna
							Locate For Alltrim(cont) == lcContCrt
							If Found()
								If Empty(lcAcontCrt)
									lcMsgCrt = "Articol " + lcDenCrt + ": contul " + lcContCrt + " are analitice definite, analiticul nu e completat."
									If !(lcMsgCrt $ lcArtMesaj)
										lcArtMesaj = lcArtMesaj + Iif(Empty(lcArtMesaj),'',Chr(13)+Chr(10)) + lcMsgCrt
									Endif
								Else
									Locate For Alltrim(cont) == lcContCrt And Alltrim(Nvl(acont,'')) == lcAcontCrt
									If !Found()
										lcMsgCrt = "Articol " + lcDenCrt + ": analiticul " + lcContCrt + "." + lcAcontCrt + " nu exista in planul de conturi."
										If !(lcMsgCrt $ lcArtMesaj)
											lcArtMesaj = lcArtMesaj + Iif(Empty(lcArtMesaj),'',Chr(13)+Chr(10)) + lcMsgCrt
										Endif
									Endif
								Endif
							Endif
							Select rul_temp
						Endscan
						If !Empty(lcArtMesaj)
							lcMesaje = lcMesaje + Iif(Empty(lcMesaje),'',Chr(13)+Chr(10)) + lcArtMesaj
						Endif
					Endif
					Use In crsPlanAna
				Endif
			Endif
		Endif
		
		Thisform.cmesajsync = lcMesaje
		Select (lcSel)
		Return Empty(lcMesaje)
	ENDPROC

	PROCEDURE chkSpargeSecundare.Valid
		*!* NU sincronizeaza() direct (eroare VFP 2166) - doar armeaza tmrSync
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE Cmd_executa1.Click
		*!* butonul benzii: sincronizare manuala
		Thisform.sincronizeaza()
	ENDPROC

	PROCEDURE Grid1.cAscc.Text1.Click
		this.LostFocus(.t.)
	ENDPROC

	PROCEDURE Grid1.cAscc.Text1.GotFocus
		*!* valoarea la intrarea in celula - Valid recalculeaza doar daca s-a modificat
		Thisform.cOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE Grid1.cAscc.Text1.LostFocus
		PARAMETERS PlClick
		lcSel = thisform.grid1.RecordSource 
		SELECT (lcSel)
		lcCont = scc
		lcAcont = ascc
		llReturn = verific_analitic(plClick, lcCont, lcAcont,'ascc', lcSel) && in oOperatii_comune.prg
	ENDPROC

	PROCEDURE Grid1.cAscc.Text1.Valid
		*!* rand S: schimbarea manuala a analiticului creditor muta si TVA-ul la resincronizare.
		*!* Garda pe nOldVal: Valid re-declansat de regenerarea randurilor din sincronizare nu
		*!* rearmeaza timerul; grila poate scrie campul INAINTE de Valid (ex. Enter), deci
		*!* armarea nu depinde de compararea cu campul
		If Thisform.lInSync
			Return
		Endif
		If This.Value = Thisform.cOldVal
			Return
		Endif
		If introdc.tip_rand == 'S'
			If !(Alltrim(This.Value) == Alltrim(Nvl(introdc.ascc,'')))
				Select introdc
				Replace ascc With This.Value
			Endif
			Thisform.lSyncPending = .T.
			Thisform.tmrSync.Interval = 1
		Endif
		Thisform.cOldVal = This.Value
	ENDPROC

	PROCEDURE Grid1.cAscd.Text1.Click
		this.LostFocus(.t.)
	ENDPROC

	PROCEDURE Grid1.cAscd.Text1.LostFocus
		PARAMETERS PlClick
		lcSel = thisform.grid1.RecordSource 
		SELECT (lcSel)
		lcCont = scd
		lcAcont = ascd
		llReturn = verific_analitic(plClick, lcCont, lcAcont,'ascd', lcSel) && in oOperatii_comune.prg
	ENDPROC

	PROCEDURE Grid1.cCurs.Text1.Valid
		*!* cursul editat se scrie explicit (ca la cSumaVal.Valid - dupa amessagebox grid-ul
		*!* nu-l mai scria in camp) si se copiaza pe randul de TVA pereche; apoi ofer
		*!* recalcularea sumei in lei din suma in valuta, ca la modificarea sumei in valuta
		*!* recalcularea se aplica pe toate randurile documentului si reface suma_doc/suma_doc_val
		Local lnSumaDinVal, lnRaspuns, lcDocKeyC, lnRecC, lnCntS, lnSLei, lnSVal, lnMinNrDocC
		If This.Value # 0
			Select introdc
			If tip_rand == 'T' And Nvl(rand_dvi,0) = 1
				Replace curs With This.Value, valuta_proprie With 1
				If This.Value <> 0
					Replace suma_val With Round(suma / This.Value, gnPval)
				Endif
				Thisform.do_executa()
				Thisform.lSyncPending = .T.
				Thisform.tmrSync.Interval = 1
				Return
			Endif
			Replace curs With This.Value
			Thisform.copiaza_valoare([curs])
			lnRecC = Recno('introdc')
			lnMinNrDocC = 99999998
			Calculate Min(Iif(Inlist(tip_rand,'B','S'), nr_doc, 99999998)) To lnMinNrDocC
			Try
				Go lnRecC In introdc
			Catch
				Go Top In introdc
			Endtry
			If nr_doc = lnMinNrDocC And in_valuta = 1
				Thisform.oact.curs = This.Value
			Endif
			If in_valuta = 1 And !Empty(Nvl(introdc.doc_key,''))
				lcDocKeyC = introdc.doc_key
				lnRecC = Recno('introdc')
				lnRaspuns = 6
				Locate For doc_key == lcDocKeyC And in_valuta = 1 And suma_val # 0 And suma <> 0 And suma <> Round(suma_val * This.Value, gnPC)
				If Found()
					lnRaspuns = amessagebox("Suma in lei difera de suma in valuta transformata in lei!" + Chr(13) + Chr(10) + ;
						"Doriti recalcularea sumelor in lei pe document?",4+32,"Diferente sume")
				Endif
				If lnRaspuns = 6
					Scan For doc_key == lcDocKeyC And in_valuta = 1 And suma_val # 0
						Replace suma With Round(suma_val * This.Value, gnPC)
					Endscan
					Calculate Cnt(), Sum(suma), Sum(suma_val) For doc_key == lcDocKeyC And tip_rand == 'S' To lnCntS, lnSLei, lnSVal
					If lnCntS = 0
						Locate For doc_key == lcDocKeyC And tip_rand == 'B'
						If Found()
							lnCntS = -1
							lnSLei = suma
							lnSVal = suma_val
						Endif
					Else
						Locate For doc_key == lcDocKeyC
					Endif
					If lnCntS <> 0
						Replace suma_doc With lnSLei, suma_doc_val With lnSVal
						Thisform.copiaza_valoare([suma_doc])
						Thisform.copiaza_valoare([suma_doc_val])
					Endif
				Endif
				Try
					Go lnRecC In introdc
				Catch
					Go Top In introdc
				Endtry
				Thisform.do_executa
			Else
				If in_valuta = 1 And suma_val # 0
					lnSumaDinVal = Round(suma_val * This.Value, gnPC)
					lnRaspuns = 6
					If suma <> 0 And suma <> lnSumaDinVal
						lnRaspuns = amessagebox("Suma in lei difera de suma in valuta transformata in lei!" + Chr(13) + Chr(10) + ;
							"Doriti recalcularea sumei in lei?",4+32,"Diferente sume")
					Endif
					If lnRaspuns = 6
						Replace suma With lnSumaDinVal
					Endif
					Thisform.do_executa
				Endif
			Endif
			Thisform.lSyncPending = .T.
			Thisform.tmrSync.Interval = 1
		Endif
	ENDPROC

	PROCEDURE Grid1.cDataAct.Text1.Valid
		Thisform.copiaza_valoare(This.Parent.ControlSource)
		
	ENDPROC

	PROCEDURE Grid1.cExplicatieTva.Combo1.Valid
		*!* 14.07.2016
		*!* marius.mutu
		*!* inlocuiesc 4426 = 401 cu 4426 = 4427 pt ach tx inversa/CE 20%
		*!* aplicarea pe cursor e delegata la aplica_explicatie_tva
		
		LOCAL lnId, lnPtva
		lnId = jtva_coloane2.id_jtva_coloana
		lnPtva = jtva_coloane2.cota_Tva
		
		Select introdc
		Replace id_jtva_coloana With lnId, ptva With lnPtva
		If Inlist(introdc.tip_rand, 'B', 'S', 'G')
			Thisform.aplica_explicatie_tva(lnId)
		Else
			If introdc.tip_rand == 'T'
				*!* explicatie aleasa direct pe randul de TVA - sincronizarea nu o realiniaza la familia bazei
				Replace expl_manual With 1
			Endif
		Endif
		
		Thisform.do_executa()
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
		
	ENDPROC

	PROCEDURE Grid1.cExplicatieTva.Text1.DblClick
		thisform.do_modifica_explicatie_tva()
	ENDPROC

	PROCEDURE Grid1.cExplicatieTva.Text1.InteractiveChange
		thisform.do_modifica_explicatie_tva()
		This.Value = introdc.explicatie_tva
	ENDPROC

	PROCEDURE Grid1.cFDoc.Text1.DblClick
		Thisform.do_modifica_fdoc()
	ENDPROC

	PROCEDURE Grid1.cFDoc.Text1.InteractiveChange
		Thisform.do_modifica_fdoc()
		This.Value = introdc.fdoc
	ENDPROC

	PROCEDURE Grid1.cFDoc.Text1.When
		*!* blocat pe randul D (diferente, fara act propriu)
		Return !(introdc.tip_rand == 'D')
	ENDPROC

	PROCEDURE Grid1.cInValuta.Check1.Valid
		*!* la debifare se sterg valuta, suma in valuta si cursul pe liniile documentului
		Select introdc
		If tip_rand == 'T' And Nvl(rand_dvi,0) = 1
			Replace in_valuta With This.Value, valuta_proprie With 1
			If This.Value = 0
				Replace id_valuta With 0, nume_val With '', curs With 0, suma_val With 0
			Endif
			Thisform.do_executa()
			Thisform.lSyncPending = .T.
			Thisform.tmrSync.Interval = 1
			Return
		Endif
		Replace in_valuta With This.Value
		Thisform.copiaza_valoare([in_valuta])
		If This.Value = 0
			Replace id_valuta With 0, nume_val With '', curs With 0, suma_val With 0, suma_doc_val With 0
			Thisform.copiaza_valoare([id_valuta])
			Thisform.copiaza_valoare([nume_val])
			Thisform.copiaza_valoare([curs])
			Thisform.copiaza_valoare([suma_val])
			Thisform.copiaza_valoare([suma_doc_val])
		Endif
		thisform.do_executa 
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE Grid1.cNract.Text1.Valid
		*!*	modificare	v 2.1.39
		Thisform.copiaza_valoare(This.Parent.ControlSource)
		*!*	IF MOD(RECNO(),2) = 1 AND RECNO() <> RECCOUNT()
		*!*		LOCAL lcSelect
		*!*		lcSelect = SELECT()
		*!*		
		*!*		SELECT introdc
		*!*		lnNract = nract
		*!*		SKIP 
		*!*		REPLACE nract WITH lnNract
		*!*		SKIP -1
		*!*		
		*!*		SELECT (lcSelect)
		*!*	ENDIF 
		*!*	modificare	v 2.1.39	^
	ENDPROC

	PROCEDURE Grid1.cNract.Text1.When
		*!* blocat pe randul D (diferente, fara act propriu)
		Return !(introdc.tip_rand == 'D')
	ENDPROC

	PROCEDURE Grid1.cPartC.Text1.Click
		* single click nu mai declanseaza cautarea partenerului (golea partenerul la
		* anulare). Re-alegerea se face pe dublu click - vezi DblClick.
	ENDPROC

	PROCEDURE Grid1.cPartC.Text1.DblClick
		* re-alegerea partenerului creditor; daca se anuleaza, pastrez valoarea veche
		Local lcSel, lnOldId, lcOldNume
		lcSel = Thisform.grid1.RecordSource
		lnOldId = &lcSel..id_partc
		lcOldNume = &lcSel..partc
		This.LostFocus(.t.)
		If Empty(&lcSel..id_partc) And lnOldId <> 0
			Select (lcSel)
			Replace id_partc With lnOldId, partc With lcOldNume
			Thisform.grid1.Refresh()
		Endif
	ENDPROC

	PROCEDURE Grid1.cPartC.Text1.InteractiveChange
		* nu mai fortez cautarea la tastare (vezi Click/DblClick)
	ENDPROC

	PROCEDURE Grid1.cPartC.Text1.LostFocus
		PARAMETERS PlClick
		
		lcSel = thisform.grid1.RecordSource 
		IF plClick OR EMPTY(&lcSel..id_partc)
			lcCont = &lcSel..scc
			llReturn = verific_partener(lcCont, 'partc','id_partc', lcSel) && in oOperatii_comune.prg
		ELSE 
			DODEFAULT()
		ENDIF 
	ENDPROC

	PROCEDURE Grid1.cPartC.Text1.Valid
		*!* propaga valoarea pe randurile aceluiasi doc_key
		LOCAL lcSelect, lcDocKey, lnIdPart, lcPart, lcCont, lnRecCurent
		lcSelect = SELECT()
		
		SELECT introdc
		*!* randul DVI are partener propriu (vama) - nu il da si nu il preia de la factura
		IF Nvl(rand_dvi,0) = 1
			SELECT (lcSelect)
			RETURN
		ENDIF
		lnRecCurent = RECNO()
		lcDocKey = doc_key
		lnIdPart = id_partc
		lcPart = partc
		lcCont = scc
		SCAN FOR !EMPTY(lcDocKey) AND doc_key == lcDocKey AND RECNO() <> lnRecCurent
			IF Nvl(rand_dvi,0) = 1
				LOOP
			ENDIF
			IF scc = lcCont AND EMPTY(id_partc)
				REPLACE id_partc WITH lnIdPart, partc WITH lcPart
			ENDIF
		ENDSCAN
		GO lnRecCurent
		
		SELECT (lcSelect)
		
	ENDPROC

	PROCEDURE Grid1.cPartC.Text1.When
		Return .T.
	ENDPROC

	PROCEDURE Grid1.cPartD.Text1.Click
		* single click nu mai declanseaza cautarea partenerului (vezi DblClick)
	ENDPROC

	PROCEDURE Grid1.cPartD.Text1.DblClick
		* re-alegerea partenerului debitor; daca se anuleaza, pastrez valoarea veche
		Local lcSel, lnOldId, lcOldNume
		lcSel = Thisform.grid1.RecordSource
		lnOldId = &lcSel..id_partd
		lcOldNume = &lcSel..partd
		This.LostFocus(.t.)
		If Empty(&lcSel..id_partd) And lnOldId <> 0
			Select (lcSel)
			Replace id_partd With lnOldId, partd With lcOldNume
			Thisform.grid1.Refresh()
		Endif
	ENDPROC

	PROCEDURE Grid1.cPartD.Text1.InteractiveChange
		* la tastare deschid cautarea de partener debitor - acelasi mecanism ca
		* re-alegerea pe dublu-click (pastreaza valoarea veche la anulare)
		This.DblClick()
		This.Value = Evaluate(Thisform.grid1.RecordSource + '.partd')
	ENDPROC

	PROCEDURE Grid1.cPartD.Text1.LostFocus
		PARAMETERS PlClick
		
		lcSel = thisform.grid1.RecordSource 
		IF plClick OR EMPTY(&lcSel..id_partd)
			lcCont = &lcSel..scd
			llReturn = verific_partener(lcCont, 'partd','id_partd', lcSel) && in oOperatii_comune.prg
		ELSE 
			DODEFAULT()
		ENDIF 
	ENDPROC

	PROCEDURE Grid1.cPartD.Text1.Valid
		*!* propaga valoarea pe randurile aceluiasi doc_key
		LOCAL lcSelect, lcDocKey, lnIdPart, lcPart, lcCont, lnRecCurent
		lcSelect = SELECT()
		
		SELECT introdc
		lnRecCurent = RECNO()
		lcDocKey = doc_key
		lnIdPart = id_partd
		lcPart = partd
		lcCont = scd
		SCAN FOR !EMPTY(lcDocKey) AND doc_key == lcDocKey AND RECNO() <> lnRecCurent
			IF scd = lcCont AND EMPTY(id_partd)
				REPLACE id_partd WITH lnIdPart, partd WITH lcPart
			ENDIF
		ENDSCAN
		GO lnRecCurent
		
		SELECT (lcSelect)
		
	ENDPROC

	PROCEDURE Grid1.cParticipaValuta.Check1.Valid
		thisform.do_executa 
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE Grid1.cScc.Text1.GotFocus
		*!* valoarea la intrarea in celula - Valid recalculeaza doar daca s-a modificat
		Thisform.cOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE Grid1.cScc.Text1.Valid
		*!* rand S: schimbarea manuala a creditorului nu seteaza mod_manual (ar bloca
		*!* sparge_document prin llAreManual) - doar rearmeaza sincronizarea, care muta si TVA-ul.
		*!* Garda pe nOldVal: Valid re-declansat de regenerarea randurilor din sincronizare nu
		*!* rearmeaza timerul; grila poate scrie campul INAINTE de Valid (ex. Enter), deci
		*!* armarea nu depinde de compararea cu campul
		If Thisform.lInSync
			Return
		Endif
		If This.Value = Thisform.cOldVal
			Return
		Endif
		If introdc.tip_rand == 'S'
			If !(Alltrim(This.Value) == Alltrim(Nvl(introdc.scc,'')))
				Select introdc
				Replace scc With This.Value
			Endif
			Thisform.lSyncPending = .T.
			Thisform.tmrSync.Interval = 1
		Endif
		Thisform.cOldVal = This.Value
	ENDPROC

	PROCEDURE Grid1.cSerie_act.Text1.Valid
		*!*	modificare	v 2.1.39
		Thisform.copiaza_valoare(This.Parent.ControlSource)
		*!*	IF MOD(RECNO(),2) = 1 AND RECNO() <> RECCOUNT()
		*!*		LOCAL lcSelect
		*!*		lcSelect = SELECT()
		*!*		
		*!*		SELECT introdc
		*!*		lnSerie_act = serie_act
		*!*		SKIP 
		*!*		REPLACE serie_act WITH lnSerie_act
		*!*		SKIP -1
		*!*		
		*!*		SELECT (lcSelect)
		*!*	ENDIF 
		*!*	modificare	v 2.1.39	^
	ENDPROC

	PROCEDURE Grid1.cSerie_act.Text1.When
		*!* blocat pe randul D (diferente, fara act propriu)
		Return !(introdc.tip_rand == 'D')
	ENDPROC

	PROCEDURE Grid1.cSuma.Text1.GotFocus
		*!* valoarea la intrarea in celula - Valid recalculeaza doar daca s-a modificat
		Thisform.nOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE Grid1.cSuma.Text1.Valid
		*!* Nu apeleaza sincronizeaza() direct (eroare VFP 2166) - marcheaza documentul si armeaza
		*!* tmrSync. suma_doc se propaga pe grup doar la editarea randului B; pe T utilizatorul
		*!* editeaza suma de TVA. Valid re-declansat de regenerarea randurilor din sincronizare iese devreme.
		If Thisform.lInSync
			Return
		Endif
		If Vartype(This.Value) <> 'N'
			Return
		Endif
		If This.Value = Thisform.nOldVal
			*!* nemodificat (ex. navigare cu sagetile) - fara recalcul si fara resincronizare
			Return
		Endif
		If Inlist(introdc.tip_rand, 'S', 'D', 'T')
			Select introdc
			Replace mod_manual With 1
			If introdc.tip_rand == 'S' And !Empty(Nvl(introdc.doc_key,''))
				*!* S modificat manual: actualizez automat totalul facturii (suma_doc) - modificarea e intentia utilizatorului
				Local lcDocKeyS, lnSLei, lnSVal, lnRecS
				Replace suma With This.Value
				lcDocKeyS = introdc.doc_key
				lnRecS = Recno('introdc')
				Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc Where doc_key == lcDocKeyS And tip_rand == 'S' Into Cursor crsSumSDoc NOFILTER
				lnSLei = Nvl(crsSumSDoc.s_lei,0)
				lnSVal = Nvl(crsSumSDoc.s_val,0)
				Use In crsSumSDoc
				Select introdc
				Go lnRecS
				If Round(lnSLei - suma_doc, gnPc) <> 0 Or Round(lnSVal - suma_doc_val, gnPval) <> 0
					Replace suma_doc With lnSLei, suma_doc_val With lnSVal
					Thisform.copiaza_valoare([suma_doc])
					Thisform.copiaza_valoare([suma_doc_val])
					If Thisform.lRecalcTva
						Thisform.recalc_tva_document(lcDocKeyS)
					Endif
				Endif
			Endif
		Else
			If introdc.tip_rand == 'B'
				Select introdc
				Replace suma_doc With suma
				Thisform.copiaza_valoare([suma_doc])
			Endif
		Endif
		thisform.do_executa
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE Grid1.cSuma.Text1.When
		*!* blocat pe randul S cu suma in valuta (editabil doar cSumaVal)
		Return !(introdc.tip_rand == 'S' And introdc.in_valuta = 1)
	ENDPROC

	PROCEDURE Grid1.cSumaVal.Text1.GotFocus
		*!* valoarea la intrarea in celula - Valid recalculeaza doar daca s-a modificat
		Thisform.nOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE Grid1.cSumaVal.Text1.KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl
		IF NKEYCODE=13 OR nKeyCode = 4 &&ENTER
			NODEFAULT 
			KEYBOARD '{DNARROW}'
		ENDIF
		
	ENDPROC

	PROCEDURE Grid1.cSumaVal.Text1.Valid
		*!* valoarea tastata se scrie explicit din This.Value (dupa amessagebox grid-ul nu o mai scrie in camp)
		Local lnSumaDinVal, lnRaspuns
		If Thisform.lInSync
			Return
		Endif
		If Vartype(This.Value) <> 'N'
			Return
		Endif
		If This.Value = Thisform.nOldVal
			*!* nemodificat (ex. navigare cu sagetile) - fara recalcul si fara resincronizare
			Return
		Endif
		If This.Value # 0
			Select introdc
			Replace suma_val With This.Value
			* folosesc cursul randului (editabil in grid) cand exista; altfel cursul facturii principale
			lnSumaDinVal = Round(This.Value * Iif(introdc.in_valuta = 1 And Nvl(introdc.curs, 0) <> 0, introdc.curs, Thisform.oact.Curs), gnPC)
			lnRaspuns = 6
			If suma <> 0 And suma <> lnSumaDinVal
				lnRaspuns = amessagebox("Suma in lei difera de suma in valuta transformata in lei!" + CHR(13) + CHR(10) + ;
					"Doriti recalcularea sumei in lei?",4+32,"Diferente sume")
			Endif
			If lnRaspuns = 6
				Replace suma With lnSumaDinVal
			Endif
		Endif
		*!* ca la Grid1.cSuma.Text1.Valid; suma_doc se propaga pe grup doar pe randul B
		If Inlist(introdc.tip_rand, 'S', 'D', 'T')
			Select introdc
			Replace mod_manual With 1
			If introdc.tip_rand == 'S' And !Empty(Nvl(introdc.doc_key,''))
				*!* S modificat manual: actualizez automat totalul facturii (suma_doc) - modificarea e intentia utilizatorului
				Local lcDocKeyS, lnSLei, lnSVal, lnRecS
				lcDocKeyS = introdc.doc_key
				lnRecS = Recno('introdc')
				Select Sum(suma) As s_lei, Sum(suma_val) As s_val From introdc Where doc_key == lcDocKeyS And tip_rand == 'S' Into Cursor crsSumSDoc NOFILTER
				lnSLei = Nvl(crsSumSDoc.s_lei,0)
				lnSVal = Nvl(crsSumSDoc.s_val,0)
				Use In crsSumSDoc
				Select introdc
				Go lnRecS
				If Round(lnSLei - suma_doc, gnPc) <> 0 Or Round(lnSVal - suma_doc_val, gnPval) <> 0
					Replace suma_doc With lnSLei, suma_doc_val With lnSVal
					Thisform.copiaza_valoare([suma_doc])
					Thisform.copiaza_valoare([suma_doc_val])
					If Thisform.lRecalcTva
						Thisform.recalc_tva_document(lcDocKeyS)
					Endif
				Endif
			Endif
		Else
			If introdc.tip_rand == 'B'
				Select introdc
				Replace suma_doc With suma, suma_doc_val With suma_val
				Thisform.copiaza_valoare([suma_doc])
				Thisform.copiaza_valoare([suma_doc_val])
			Endif
		Endif
		Thisform.do_executa
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE Grid1.cSumaVal.Text1.When
		*!* blocat pe randul S cu suma in lei (editabil doar cSuma)
		Return !(introdc.tip_rand == 'S' And introdc.in_valuta = 0)
	ENDPROC

	PROCEDURE Grid1.cTaxCode.Text1.InteractiveChange
		If tact.cu_tva = 1
			*!*	modificare	ROACONT v 2.4.4
			If TYPE('tact.tipnota') = 'N' AND tact.tipnota = 1
				*!*	explicatii TVA exigibile din JC ( 1 ), JV ( 3 ) sau toate ( 5 )
				locauta = caut_explicatie_tva(Nvl(tact.id_jtva_coloana,-1),,,iif(tact.scc=[4428],1,iif(tact.scd=[4428],3,5)))
			Else
				locauta = caut_explicatie_tva(Nvl(tact.id_jtva_coloana,-1))
			Endif
			*!*		locauta = caut_explicatie_tva(Nvl(tact.id_jtva_coloana,-1))
			*!*	modificare	ROACONT v 2.4.4	^
			If !Empty(locauta.id_jtva_coloana)
				Select tact
				Replace id_jtva_coloana With locauta.id_jtva_coloana,explicatie_Tva With locauta.denumire,proc_tva With (locauta.cota_tva + 100) / 100
			Endif
		
			* Actualizez Cod Taxa SAFT in functie de Cota TVA
			Thisform.UpdateExplicatieSAFT()
		ENDIF
		
		
	ENDPROC

	PROCEDURE Grid1.cValuta.Text1.DblClick
		* alegerea valutei pe rand (caut_valuta, ca in dialogul Adauga factura);
		* la anulare raman valorile vechi; valoarea se copiaza pe randul de TVA pereche
		Local loCauta, llDviRon, llDocRon, llCoincideDoc
		loCauta = caut_valuta(, .F., .F.)
		If Vartype(loCauta) = 'O' And !Empty(Nvl(loCauta.id_valuta, 0))
			Select introdc
			If tip_rand == 'T' And Nvl(rand_dvi,0) = 1
				llDviRon = (Empty(Alltrim(Nvl(loCauta.nume_val,''))) Or Upper(Alltrim(Nvl(loCauta.nume_val,''))) == 'RON')
				llDocRon = (Empty(Alltrim(Nvl(Thisform.oact.nume_val,''))) Or Upper(Alltrim(Nvl(Thisform.oact.nume_val,''))) == 'RON')
				llCoincideDoc = Iif(llDviRon And llDocRon, .T., (loCauta.id_valuta == Nvl(Thisform.oact.id_valuta,0)))
				Replace id_valuta With loCauta.id_valuta, nume_val With Alltrim(loCauta.nume_val), ;
					valuta_proprie With Iif(llCoincideDoc, 0, 1)
				If llCoincideDoc
					Replace in_valuta With Iif(llDocRon, 0, 1), curs With Iif(llDocRon, 0, Thisform.oact.Curs)
					Replace suma_val With Iif(!llDocRon And curs <> 0, Round(suma / curs, gnPval), 0)
				Endif
				This.Value = introdc.nume_val
				Thisform.do_executa()
				Thisform.grid1.Refresh()
				Return
			Endif
			Replace id_valuta With loCauta.id_valuta, nume_val With Alltrim(loCauta.nume_val)
			Thisform.copiaza_valoare([id_valuta])
			Thisform.copiaza_valoare([nume_val])
			This.Value = introdc.nume_val
			Thisform.grid1.Refresh()
		Endif
	ENDPROC

	PROCEDURE Grid1.cValuta.Text1.InteractiveChange
		* la tastare deschid cautarea de valuta - acelasi mecanism ca dublu-click
		This.DblClick()
		This.Value = introdc.nume_val
	ENDPROC

	PROCEDURE Grid1.Init
		*!* italic pe randul T
		thisform.grid1.SetAll("dynamicbackcolor", "", "Column")
		thisform.grid1.SetAll("dynamicforecolor", "", "Column")
		thisform.grid1.SetAll("DynamicBackColor", "introdc.doc_color", "Column")
		thisform.grid1.SetAll("DynamicFontItalic", "introdc.tip_rand == 'T'", "Column")
		*!* gri pe coloanele blocate dinamic (vezi metodele .When)
		thisform.grid1.cSuma.DynamicBackColor = "Iif(introdc.tip_rand = 'S' And introdc.in_valuta = 1, Rgb(229,229,229), introdc.doc_color)"
		thisform.grid1.cSumaVal.DynamicBackColor = "Iif(introdc.tip_rand = 'S' And introdc.in_valuta = 0, Rgb(229,229,229), introdc.doc_color)"
		thisform.grid1.cSerie_act.DynamicBackColor = "Iif(introdc.tip_rand = 'D', Rgb(229,229,229), introdc.doc_color)"
		thisform.grid1.cNract.DynamicBackColor = "Iif(introdc.tip_rand = 'D', Rgb(229,229,229), introdc.doc_color)"
		thisform.grid1.cFDoc.DynamicBackColor = "Iif(introdc.tip_rand = 'D', Rgb(229,229,229), introdc.doc_color)"
	ENDPROC

	PROCEDURE GridArt.cCant.Text1.GotFocus
		Thisform.nOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE GridArt.cCant.Text1.InteractiveChange
		*!*	DODEFAULT()
		*!*	this.LostFocus(.T.)
		
	ENDPROC

	PROCEDURE GridArt.cCant.Text1.LostFocus
		PARAMETERS tlCalcul
		
		If This.Value = Thisform.nOldVal
			&& nemodificat - fara recalcul
			Return
		Endif
		REPLACE cant WITH this.Value
		lnRec = RECNO()
		thisform.do_executa_pret(3,lnRec,this.value)
	ENDPROC

	PROCEDURE GridArt.cCotaTva.Text1.GotFocus
		*!* valoarea la intrarea in celula - Valid rearmeaza sincronizarea doar daca s-a modificat
		Thisform.nOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE GridArt.cCotaTva.Text1.Valid
		*!* editarea cotei TVA nu recalculeaza direct - armeaza sincronizarea amanata,
		*!* care regenereaza randurile T pe cota
		If This.Value = Thisform.nOldVal
			Return
		Endif
		Thisform.lSyncPending = .T.
		Thisform.tmrSync.Interval = 1
	ENDPROC

	PROCEDURE GridArt.Column1.Text1.LostFocus
		Parameters tlCalcul
		
		*IF tlCalcul
		
		*	REPLACE pret_val WITH this.Value
		lnRec = Recno()
		*!*		thisform.do_executa_pret(3,lnRec,this.Value)
		*!*	modificare	v 2.1.37
		*!*		thisform.do_executa_pret(1,lnRec,pret_val)
		If Thisform.lIntern
			Thisform.do_executa_pret(1,lnRec,pret_lei)
		Else
			Thisform.do_executa_pret(1,lnRec,pret_val)
		Endif
		*!*	modificare	v 2.1.37	^
		*ENDIF
	ENDPROC

	PROCEDURE GridArt.cPretFactura.Text1.GotFocus
		Thisform.nOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE GridArt.cPretFactura.Text1.InteractiveChange
		*!*	DODEFAULT()
		*!*	this.LostFocus(.t.)
		
	ENDPROC

	PROCEDURE GridArt.cPretFactura.Text1.LostFocus
		PARAMETERS tlCalcul
		
		If This.Value = Thisform.nOldVal
			&& nemodificat - fara recalcul
			Return
		Endif
		*IF tlCalcul
			
		*	REPLACE pret_val WITH this.Value 
			lnRec = RECNO()
			thisform.do_executa_pret(1,lnRec,this.Value)
		*ENDIF 
	ENDPROC

	PROCEDURE GridArt.cPretLeiCalculat.Text1.GotFocus
		Thisform.nOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE GridArt.cPretLeiCalculat.Text1.InteractiveChange
		*!*	DODEFAULT()
		*!*	this.LostFocus(.t.)
	ENDPROC

	PROCEDURE GridArt.cPretLeiCalculat.Text1.LostFocus
		PARAMETERS tlCalcul
		
		If This.Value = Thisform.nOldVal
			&& nemodificat - fara recalcul
			Return
		Endif
		REPLACE pret WITH this.Value
		lnRec = RECNO()
		thisform.do_executa_pret(3,lnRec,this.Value)
	ENDPROC

	PROCEDURE GridArt.cPretValutaCalculat.Text1.GotFocus
		Thisform.nOldVal = This.Value
		Dodefault()
	ENDPROC

	PROCEDURE GridArt.cPretValutaCalculat.Text1.InteractiveChange
		*!*	DODEFAULT()
		*!*	this.LostFocus(.t.)
	ENDPROC

	PROCEDURE GridArt.cPretValutaCalculat.Text1.LostFocus
		PARAMETERS tlCalcul
		
		If This.Value = Thisform.nOldVal
			&& nemodificat - fara recalcul
			Return
		Endif
		lnRec = RECNO()
		thisform.do_executa_pret(2,lnRec,this.value)
	ENDPROC

	PROCEDURE tmrSync.Timer
		*!* executa sincronizarea amanata armata din Valid-urile de grid;
		*!* Interval=0 opreste repetarea pana la urmatoarea armare
		If Thisform.lSyncPending
			Thisform.lSyncPending = .F.
			This.Interval = 0
			Thisform.sincronizeaza()
		Endif
	ENDPROC

ENDDEFINE

DEFINE CLASS nir AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="_shapeSus" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura1.txfTotal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura1.txfBaza" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura1.txfTva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_discount1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_shape3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_shapeDr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Urmator1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lbTotal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txNir" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_adaos1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.But_nou1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.lb_listePreturi" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.cboListe" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.Cb_tx_gestout" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1.Cb_tx_gestin" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1.But_sterge1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura2.lb_curs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura2.lb_valuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="tx_totalctva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_totalctva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Container_valoare_decontata1" UniqueID="" Timestamp="" />

	#INCLUDE "..\include\foxpro.h"
	*<DefinedPropArrayMethod>
		*m: aleg_cont_transfer
		*m: analiza_cmp
		*m: assign_analitic
		*m: assign_values
		*m: bon_fiscal
		*m: calcul_pret_vanzare
		*m: calcul_sume
		*m: caut_gestiune
		*m: compensare
		*m: do_verifica_sume
		*m: intrare_produs
		*m: modificare_lista_preturi
		*p: cfrm_ceredate
		*p: cobj
		*p: ctip_frm
		*p: nftotctva
		*p: nftotftva
		*p: nftottva
		*p: nidresponsabil
		*p: nresp
		*p: ntotal
		*p: ntvaincasare
		*p: omemopref		&& Obiectul in care se retin preferintele : id_jtva_ach, proc_tva, id_jtva_vanz, proc_tvav
		*p: osel_dr
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		cbuton3 = 
		cbuton4 = Ct_grid_order1.But_sterge1;but_reface1
		cfrm_ceredate = 
		cobj = 
		ctip_frm = NIR
		DoCreate = .T.
		Height = 572
		lactiv3 = .T.
		lactiv4 = .T.
		Name = "nir"
		nftotctva = 0.00
		nftotftva = 0.00
		nftottva = 0.00
		nidresponsabil = 0
		nresp = 
		ntotal = 0
		ntvaincasare = 0
		omemopref = .NULL.
		osel_dr = 
		Width = 793
		WindowType = 1
		_memberdata = <VFPData>
			<memberdata name="nidresponsabil" display="nIdResponsabil"/>
			<memberdata name="nresp" display="nResp"/>
		</VFPData>
		_shape1.Anchor = 11
		_shape1.Height = 30
		_shape1.Left = -1
		_shape1.Name = "_shape1"
		_shape1.Tag = ""
		_shape1.Top = -1
		_shape1.Width = 726
		_shape1.ZOrderSet = 4
		_shape2.Anchor = 9
		_shape2.Height = 29
		_shape2.Left = 724
		_shape2.Name = "_shape2"
		_shape2.Tag = "MOVABLE"
		_shape2.Top = 0
		_shape2.Width = 69
		_shape2.ZOrderSet = 7
		Lb_titlu_alb_b121.Anchor = 3
		Lb_titlu_alb_b121.FontName = "Comic Sans MS"
		Lb_titlu_alb_b121.FontSize = 10
		Lb_titlu_alb_b121.Height = 20
		Lb_titlu_alb_b121.Left = 10
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 5
		Lb_titlu_alb_b121.Top = 3
		Lb_titlu_alb_b121.Width = 41
		Lb_titlu_alb_b121.ZOrderSet = 9
		BUT_TERMIN1.Anchor = 9
		BUT_TERMIN1.Height = 27
		BUT_TERMIN1.Left = 757
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 3
		BUT_TERMIN1.Tag = ""
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.Width = 32
		BUT_TERMIN1.ZOrderSet = 13
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT '_shape3' AS _shape WITH ;
		Anchor = 135, ;
		BackStyle = 0, ;
		BorderColor = 7,118,177, ;
		BorderWidth = 2, ;
		Height = 408, ;
		Left = 9, ;
		Name = "_shape3", ;
		Tag = "", ;
		Top = 156, ;
		Width = 361, ;
		ZOrderSet = 3
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT '_shapeDr' AS _shape WITH ;
		Anchor = 45, ;
		BackStyle = 0, ;
		BorderColor = 7,118,177, ;
		BorderWidth = 2, ;
		Height = 408, ;
		Left = 406, ;
		Name = "_shapeDr", ;
		Tag = "", ;
		Top = 156, ;
		Width = 381, ;
		ZOrderSet = 5
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT '_shapeSus' AS _shape WITH ;
		Anchor = 11, ;
		BackStyle = 0, ;
		BorderColor = 7,118,177, ;
		BorderWidth = 2, ;
		Height = 123, ;
		Left = 9, ;
		Name = "_shapeSus", ;
		Tag = "RESIZABLE, MOVABLE", ;
		Top = 32, ;
		Width = 778, ;
		ZOrderSet = 0
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Anchor = 9, ;
		Left = 727, ;
		Name = "But_renunt1", ;
		TabIndex = 4, ;
		Tag = "", ;
		Top = 1, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Container_valoare_decontata1' AS container_valoare_decontata WITH ;
		Left = 15, ;
		Name = "Container_valoare_decontata1", ;
		Top = 81, ;
		Visible = .F., ;
		ZOrderSet = 20, ;
		Label1.Name = "Label1", ;
		Text1.Name = "Text1"
		*< END OBJECT: ClassLib="ointroduceri.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_adaos1' AS ct_adaos WITH ;
		Anchor = 9, ;
		Left = 538, ;
		Name = "Ct_adaos1", ;
		TabIndex = 8, ;
		Tag = "", ;
		Top = 38, ;
		ZOrderSet = 14, ;
		LBBAZA_ADAOS.Name = "LBBAZA_ADAOS", ;
		LBTVA_ADAOS.Name = "LBTVA_ADAOS", ;
		LBPROC_ADAOS.Name = "LBPROC_ADAOS", ;
		TXBAZA_ADAOS.ControlSource = "this.parent.baza_adaos", ;
		TXBAZA_ADAOS.Name = "TXBAZA_ADAOS", ;
		TXTVA_ADAOS.Name = "TXTVA_ADAOS", ;
		TXPROC_ADAOS.Name = "TXPROC_ADAOS"
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_discount1' AS ct_discount WITH ;
		Anchor = 3, ;
		Height = 112, ;
		Left = 286, ;
		Name = "Ct_discount1", ;
		TabIndex = 10, ;
		Tag = "", ;
		Top = 37, ;
		Width = 284, ;
		ZOrderSet = 2, ;
		COMBOGRID3.Name = "COMBOGRID3", ;
		LBBAZA_DISCOUNT.Name = "LBBAZA_DISCOUNT", ;
		LBTVA_DISCOUNT.Name = "LBTVA_DISCOUNT", ;
		LBPROC_DISCOUNT.Name = "LBPROC_DISCOUNT", ;
		TXBAZA_DISCOUNT.Name = "TXBAZA_DISCOUNT", ;
		TXTVA_DISCOUNT.Name = "TXTVA_DISCOUNT", ;
		TXPROC_DISCOUNT.Format = "r", ;
		TXPROC_DISCOUNT.InputMask = (get_mask(12,2)), ;
		TXPROC_DISCOUNT.Name = "TXPROC_DISCOUNT", ;
		CotaTVA.HideSelection = .F., ;
		CotaTVA.Name = "CotaTVA", ;
		lbTva.Name = "lbTva", ;
		lb_explicatie_tva.Left = 1, ;
		lb_explicatie_tva.Name = "lb_explicatie_tva", ;
		lb_explicatie_tva.Top = 91
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_factura1' AS ct_factura WITH ;
		Anchor = 131, ;
		Height = 71, ;
		Left = 14, ;
		Name = "Ct_factura1", ;
		TabIndex = 9, ;
		Tag = "", ;
		Top = 61, ;
		Width = 292, ;
		ZOrderSet = 1, ;
		lbBaza.Left = 4, ;
		lbBaza.Name = "lbBaza", ;
		lbBaza.Top = 27, ;
		LbTva.Left = 4, ;
		LbTva.Name = "LbTva", ;
		LbTva.Top = 50, ;
		txBaza.ControlSource = "this.parent.totftva", ;
		txBaza.Height = 23, ;
		txBaza.Left = 99, ;
		txBaza.Name = "txBaza", ;
		txBaza.ToolTipText = "Valoarea fara TVA calculata", ;
		txBaza.Top = 25, ;
		txBaza.Width = 91, ;
		txTva.ControlSource = "this.parent.tva", ;
		txTva.Height = 23, ;
		txTva.Left = 99, ;
		txTva.Name = "txTva", ;
		txTva.ToolTipText = "Valoarea TVA calculata", ;
		txTva.Top = 48, ;
		txTva.Width = 91, ;
		lbExplic.AutoSize = .F., ;
		lbExplic.Left = 6, ;
		lbExplic.Name = "lbExplic", ;
		lbExplic.Top = 14, ;
		txTotal.Height = 23, ;
		txTotal.Left = 99, ;
		txTotal.Name = "txTotal", ;
		txTotal.ToolTipText = "Valoarea cu TVA calculata", ;
		txTotal.Top = 1, ;
		txTotal.Width = 91, ;
		lbTotal.AutoSize = .F., ;
		lbTotal.Left = 3, ;
		lbTotal.Name = "lbTotal", ;
		lbTotal.Top = 3
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_factura1.txfBaza' AS _txbase WITH ;
		BackColor = 206,231,255, ;
		ControlSource = "thisform.nfTotftva", ;
		Format = "KR", ;
		Height = 23, ;
		InputMask = (get_mask(9,gnPC)), ;
		Left = 192, ;
		Name = "txfBaza", ;
		ToolTipText = "Valoarea fara TVA de pe factura - modificati daca este diferita de valoarea calculata", ;
		Top = 25, ;
		Visible = .F., ;
		Width = 96
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'Ct_factura1.txfTotal' AS _txbase WITH ;
		ControlSource = "thisform.nfTotctva", ;
		DisabledBackColor = 255,255,255, ;
		Format = "RK", ;
		Height = 23, ;
		InputMask = (get_mask(9,gnPC)), ;
		Left = 192, ;
		Name = "txfTotal", ;
		ReadOnly = .T., ;
		ToolTipText = "Valoarea cu TVA de pe factura", ;
		Top = 1, ;
		Visible = .F., ;
		Width = 96
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'Ct_factura1.txfTva' AS _txbase WITH ;
		BackColor = 206,231,255, ;
		ControlSource = "thisform.nfTottva", ;
		Format = "KR", ;
		Height = 23, ;
		InputMask = (get_mask(9,gnPC)), ;
		Left = 192, ;
		Name = "txfTva", ;
		ToolTipText = "Valoarea TVA de pe factura - modificati daca este diferita de valoarea calculata", ;
		Top = 48, ;
		Visible = .F., ;
		Width = 96
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'Ct_factura2' AS ct_factura WITH ;
		Anchor = 3, ;
		Height = 96, ;
		Left = 285, ;
		Name = "Ct_factura2", ;
		TabIndex = 9, ;
		Tag = "", ;
		Top = 45, ;
		Width = 270, ;
		ZOrderSet = 17, ;
		LBBAZA.Left = 51, ;
		LBBAZA.Name = "LBBAZA", ;
		LBBAZA.Top = 52, ;
		LBTVA.Left = 51, ;
		LBTVA.Name = "LBTVA", ;
		LBTVA.Top = 72, ;
		TXBAZA.Height = 23, ;
		TXBAZA.InputMask = (get_mask(14,gnPVal)), ;
		TXBAZA.Left = 130, ;
		TXBAZA.Name = "TXBAZA", ;
		TXBAZA.Top = 50, ;
		TXBAZA.Width = 138, ;
		TXTVA.Height = 23, ;
		TXTVA.InputMask = (get_mask(14,gnPVal)), ;
		TXTVA.Left = 130, ;
		TXTVA.Name = "TXTVA", ;
		TXTVA.Top = 70, ;
		TXTVA.Width = 138, ;
		LBEXPLIC.Left = 1, ;
		LBEXPLIC.Name = "LBEXPLIC", ;
		LBEXPLIC.Top = 52, ;
		TXTOTAL.ControlSource = "this.parent.totctva", ;
		TXTOTAL.Height = 23, ;
		TXTOTAL.InputMask = (get_mask(14,gnPVal)), ;
		TXTOTAL.Left = 130, ;
		TXTOTAL.Name = "TXTOTAL", ;
		TXTOTAL.Top = 28, ;
		TXTOTAL.Width = 138, ;
		LBTOTAL.Height = 18, ;
		LBTOTAL.Left = 3, ;
		LBTOTAL.Name = "LBTOTAL", ;
		LBTOTAL.Top = 19, ;
		LBTOTAL.Width = 106
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_factura2.lb_curs' AS lb_titlu_albastru_b12 WITH ;
		Alignment = 2, ;
		AutoSize = .F., ;
		Caption = "[Curs]", ;
		FontBold = .T., ;
		Height = 22, ;
		Left = 19, ;
		Name = "lb_curs", ;
		Top = 2, ;
		Width = 201
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'Ct_factura2.lb_valuta' AS lb_titlu_albastru_b12 WITH ;
		Caption = "[Valuta]", ;
		FontBold = .F., ;
		FontSize = 9, ;
		ForeColor = 7,118,177, ;
		Height = 17, ;
		Left = 58, ;
		Name = "lb_valuta", ;
		Top = 35, ;
		Width = 42
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'Ct_grid_order1' AS ct_grid_order WITH ;
		Anchor = 45, ;
		cnumecursor = rul_temp1, ;
		Height = 425, ;
		Left = 409, ;
		Name = "Ct_grid_order1", ;
		TabIndex = 11, ;
		Top = 139, ;
		Width = 375, ;
		ZOrderSet = 16, ;
		_GRID1.Height = 325, ;
		_GRID1.Left = 6, ;
		_GRID1.Name = "_GRID1", ;
		_GRID1.TabIndex = 2, ;
		_GRID1.Top = 93, ;
		_GRID1.Width = 364, ;
		Titlu.Left = 9, ;
		Titlu.Name = "Titlu", ;
		Titlu.TabIndex = 3, ;
		Titlu.Top = 28, ;
		Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Cb_tx_cautare1.Left = 7, ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.TabIndex = 1, ;
		Cb_tx_cautare1.Text.Name = "Text", ;
		Cb_tx_cautare1.Top = 65
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_order1.But_sterge1' AS but_sterge WITH ;
		Anchor = 9, ;
		Left = 310, ;
		Name = "But_sterge1", ;
		TabIndex = 5, ;
		TabStop = .F., ;
		Top = 65, ;
		Visible = .T.
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_grid_order1.Cb_tx_gestin' AS cb_tx_simplu WITH ;
		BackStyle = 0, ;
		BorderColor = 255,255,255, ;
		Height = 24, ;
		Left = 7, ;
		Name = "Cb_tx_gestin", ;
		TabIndex = 4, ;
		Top = 40, ;
		Width = 366, ;
		_CBBASE1.BorderStyle = 0, ;
		_CBBASE1.ColumnCount = 2, ;
		_CBBASE1.ColumnLines = .F., ;
		_CBBASE1.ColumnWidths = "220,40", ;
		_CBBASE1.ControlSource = "poact.gestin", ;
		_CBBASE1.FontItalic = .F., ;
		_CBBASE1.FontName = "Arial Narrow", ;
		_CBBASE1.Height = 23, ;
		_CBBASE1.Left = 130, ;
		_CBBASE1.Name = "_CBBASE1", ;
		_CBBASE1.RowSource = "nom_gestiuni.nume_gestiune,cgest", ;
		_CBBASE1.RowSourceType = 6, ;
		_CBBASE1.Sorted = .F., ;
		_CBBASE1.Top = 0, ;
		_CBBASE1.Width = 229, ;
		_LBBASE1.Caption = "Gestiunea destinatie", ;
		_LBBASE1.FontItalic = .T., ;
		_LBBASE1.Left = 3, ;
		_LBBASE1.Name = "_LBBASE1", ;
		_LBBASE1.Top = 4
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search1' AS ct_grid_search WITH ;
		Anchor = 135, ;
		cnumecursor = cursor_curent1, ;
		Height = 418, ;
		Left = 11, ;
		Name = "Ct_grid_search1", ;
		TabIndex = 1, ;
		Top = 140, ;
		Width = 357, ;
		ZOrderSet = 15, ;
		_GRID1.Comment = "grd_st", ;
		_GRID1.Height = 324, ;
		_GRID1.Left = 6, ;
		_GRID1.Name = "_GRID1", ;
		_GRID1.RecordSource = "cursor_curent", ;
		_GRID1.TabIndex = 3, ;
		_GRID1.Top = 94, ;
		_GRID1.Width = 347, ;
		_GRID1.ZOrderSet = 0, ;
		Titlu.Left = 9, ;
		Titlu.Name = "Titlu", ;
		Titlu.TabIndex = 4, ;
		Titlu.Top = 24, ;
		Titlu.ZOrderSet = 1, ;
		Cb_tx_cautare1.Criteriu.Comment = "criteriu_st", ;
		Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Cb_tx_cautare1.Height = 27, ;
		Cb_tx_cautare1.Left = 7, ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.TabIndex = 2, ;
		Cb_tx_cautare1.Text.Comment = "text_st", ;
		Cb_tx_cautare1.Text.Height = 25, ;
		Cb_tx_cautare1.Text.Left = 103, ;
		Cb_tx_cautare1.Text.Name = "Text", ;
		Cb_tx_cautare1.Text.Top = 1, ;
		Cb_tx_cautare1.Text.Width = 207, ;
		Cb_tx_cautare1.Top = 66, ;
		Cb_tx_cautare1.Width = 312, ;
		Cb_tx_cautare1.ZOrderSet = 2
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search1.But_nou1' AS but_nou WITH ;
		Anchor = 9, ;
		Height = 27, ;
		Left = 322, ;
		Name = "But_nou1", ;
		TabIndex = 6, ;
		TabStop = .F., ;
		Top = 65, ;
		ZOrderSet = 3
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_grid_search1.Cb_tx_gestout' AS cb_tx_simplu WITH ;
		BackStyle = 0, ;
		BorderColor = 255,255,255, ;
		Height = 24, ;
		Left = 7, ;
		Name = "Cb_tx_gestout", ;
		TabIndex = 5, ;
		Top = 38, ;
		Width = 346, ;
		ZOrderSet = 6, ;
		_CBBASE1.BorderStyle = 0, ;
		_CBBASE1.ColumnCount = 2, ;
		_CBBASE1.ColumnLines = .F., ;
		_CBBASE1.ColumnWidths = "180,30", ;
		_CBBASE1.ControlSource = "poact.gestout", ;
		_CBBASE1.FontItalic = .F., ;
		_CBBASE1.FontName = "Arial Narrow", ;
		_CBBASE1.Height = 23, ;
		_CBBASE1.Left = 101, ;
		_CBBASE1.Name = "_CBBASE1", ;
		_CBBASE1.RowSource = "nom_gestiuni.nume_gestiune,cgest", ;
		_CBBASE1.RowSourceType = 6, ;
		_CBBASE1.Sorted = .F., ;
		_CBBASE1.Top = 1, ;
		_CBBASE1.Width = 243, ;
		_LBBASE1.Caption = "Gestiunea sursa", ;
		_LBBASE1.FontItalic = .T., ;
		_LBBASE1.Left = 3, ;
		_LBBASE1.Name = "_LBBASE1", ;
		_LBBASE1.Top = 3
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search1.cboListe' AS combobox WITH ;
		Anchor = 3, ;
		BorderStyle = 0, ;
		ColumnCount = 4, ;
		ColumnLines = .F., ;
		ColumnWidths = "200,65,60,0", ;
		Format = "", ;
		Height = 23, ;
		Left = 104, ;
		Name = "cboListe", ;
		RowSource = "cListePret.nume_lista_preturi,datai,datas,id_pol", ;
		RowSourceType = 2, ;
		Style = 2, ;
		TabIndex = 1, ;
		Top = 39, ;
		Visible = .F., ;
		Width = 247, ;
		ZOrderSet = 5
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'Ct_grid_search1.lb_listePreturi' AS label WITH ;
		Anchor = 3, ;
		BackStyle = 0, ;
		Caption = "Lista de preturi:", ;
		FontItalic = .T., ;
		Height = 17, ;
		Left = 11, ;
		Name = "lb_listePreturi", ;
		TabIndex = 7, ;
		Top = 42, ;
		Visible = .F., ;
		Width = 84, ;
		ZOrderSet = 4
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'lb_totalctva' AS lb_simplu WITH ;
		Anchor = 9, ;
		Caption = "Total val.vânz. cu TVA", ;
		ForeColor = 7,118,177, ;
		Left = 542, ;
		Name = "lb_totalctva", ;
		Top = 119, ;
		Visible = .F., ;
		ZOrderSet = 19
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'lbTotal' AS titlufrumos WITH ;
		Anchor = 3, ;
		AutoSize = .F., ;
		Caption = "TOTAL NIR:", ;
		ForeColor = 7,118,177, ;
		Height = 20, ;
		Left = 17, ;
		Name = "lbTotal", ;
		TabIndex = 6, ;
		Top = 40, ;
		Width = 77, ;
		ZOrderSet = 11
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="label" />

	ADD OBJECT 'tx_totalctva' AS _txbase WITH ;
		Alignment = 3, ;
		Anchor = 9, ;
		Height = 23, ;
		InputMask = (get_mask(12,gnPc)), ;
		Left = 665, ;
		Name = "tx_totalctva", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		TabStop = .F., ;
		Top = 117, ;
		Value = 0, ;
		Visible = .F., ;
		Width = 113, ;
		ZOrderSet = 18
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'txNir' AS _txbase WITH ;
		Anchor = 3, ;
		BackStyle = 1, ;
		ControlSource = "thisform.ntotal", ;
		DisabledBackColor = 255,255,255, ;
		FontCharSet = 238, ;
		Height = 21, ;
		InputMask = (get_mask(12,gnPc)), ;
		Left = 114, ;
		Name = "txNir", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		TabIndex = 7, ;
		Tag = "", ;
		Top = 39, ;
		Width = 147, ;
		ZOrderSet = 12
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'Urmator1' AS urmator WITH ;
		Anchor = 240, ;
		Left = 373, ;
		Name = "Urmator1", ;
		TabIndex = 2, ;
		Tag = "", ;
		Top = 324, ;
		ZOrderSet = 10, ;
		Imbuton1.Height = 27, ;
		Imbuton1.Name = "Imbuton1", ;
		Imbuton1.Width = 30, ;
		Command1.Name = "Command1"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />
	
	PROCEDURE Activate
		this.WindowState = 2
	ENDPROC

	PROCEDURE aleg_cont_transfer
		PARAMETERS tnIdGest
		lcSql = [select (case when p.explicatie is null then s.explicatie else p.explicatie end) as explicatie,] +;
				[c.cont, p.acont from VCORESP_CONT_TIPGEST c ] +; 
				[left join vplcont_analitic p on c.cont = p.cont and p.an = ?gnAn ] +;
				[left join vplcont_sintetic s on c.cont = s.cont and s.an = ?gnAn]
		
		pcFiltruOrig = [c.id_tipgest in (select nr_pag from  vnom_gestiuni where id_gestiune = ?tnIdGest)] 
		pcfiltru = [1=2]
		pcschema = []
		pcorder = [cont,acont]
		pccoloane = [cont,acont,explicatie]
		pcTitlu = [Alegeti Contul de Transfer] 
		pcTitluColoane = [Cont,Analitic,Explicatie cont]
		locauta = cauta_alfa(lcSql,pcfiltru,pcschema,pcorder,pccoloane,pcTitlu,pcTitluColoane,'',.F.,pcFiltruOrig)		&& 11.07.2007
			
		RETURN loCauta
	ENDPROC

	PROCEDURE analiza_cmp
		PARAMETERS tcRul, tcAct
		
		*!* 14.10.2006
		*!* mutu.marius
		*!* tratare achizitie articol cu mai multe preturi
		
		LOCAL lcSql, lcCursor, lnSucces
		PRIVATE poArticol
		*** alocare numar NIR pt rulajele generate de CMP
		
		*** dezaloc in caz ca trece de mai multe ori prin metoda asta
		IF THISFORM.numar_plaja1.id_numar # 0
			THISFORM.numar_plaja1.dezalocare_numar()
		ENDIF
		
		lnIdEnt = 0
		THIS.numar_plaja1.id_entitate = lnIdEnt
		THIS.numar_plaja1.tip = 4 && NIR PT CMP
		THIS.numar_plaja1.serie = 2 && Asa transmit paramerii la procedura viz_config_serii din oproceduri_configurare.prg
		THIS.numar_plaja1.alocare_numar()
		lnNnir = THIS.numar_plaja1.numar_curent
		***
		
		SELECT * ;
			FROM (tcRul) WITH (BUFFERING = .T.) ;
			INTO CURSOR crsTempRul
		
		SELECT DISTINCT ID_ARTICOL, CONT FROM crsTempRul ;
			INTO CURSOR crsArticoleTemp
		
		&& pentru fiecare articol - se poate sa am acelasi articol cu mai multe preturi
		SELECT crsArticoleTemp
		SCAN
			SCATTER NAME poArticol
		
			&& selectez din stoc cantitatea si pretul existente pentru articolul curent
			&& posibil mai multe gestiuni ???
			lcSql = [SELECT cants+cant-cante as cante, pret, id_articol, id_gestiune, id_gestiune as id_gestout, cont,] + ;
				[acont FROM stoc where an = ?gnAn and luna = ?gnluna and id_articol = ?poArticol.id_articol ] + ;
				[and (cants+cant-cante)<>0 and TRIM(cont) = ?ALLTRIM(poArticol.cont)] + gcCondSucursala
			lcCursorStoc = [tmpVer]
			lnSucces = goExecutor.oExecute(lcSql, lcCursorStoc)
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
				RETURN
			ENDIF
		
			&& pentru fiecare pozitie articol achizitionat din articolul curent
			SELECT crsTempRul
			SCAN FOR cant <> 0 AND id_articol = poArticol.id_articol
				SCATTER NAME orul
		
				&& scot articolul curent din rulaj la pretul de achizitie
		*!*		IF RECCOUNT(lcCursorStoc) > 0
				&& il scot chiar daca nu il am in stoc - pentru ca s-ar putea sa fie achizitionat cu mai multe preturi
					SELECT (tcRul)
					APPEND BLANK
					GATHER NAME orul
					REPLACE cante WITH orul.cant, cant WITH 0, nnir WITH lnNnir, tva WITH 0
					REPLACE id_tip_rulaj WITH 2 && RULAJ ARTIFICIAL CMP
		*!*		ENDIF
		
				SELECT crsTempRul
			ENDSCAN
		
		
			*** scot din stoc articolul curent - cantitatea si pretul existente - inainte de achizitia curenta
			IF USED(lcCursorStoc)
				SELECT (lcCursorStoc)
				SCAN
					SCATTER NAME ointr
					SELECT (tcRul)
					APPEND BLANK
					GATHER NAME orul
					REPLACE cant WITH 0, cante WITH 0
					GATHER NAME ointr
					REPLACE nnir WITH lnNnir
					REPLACE id_tip_rulaj WITH 2 && RULAJ ARTIFICIAL CMP
					SELECT (lcCursorStoc)
				ENDSCAN
				USE IN (lcCursorStoc)
			ENDIF 	
		
			&& aflu pretul mediu ponderat - selectez toate iesirile din rul_temp (articolele achizitionate si stocul precedent)
			&& pentru articol, cont curente
			&& un singur pret mediu ponderat pe articol, indiferent de gestiune
			*!* 05.12.2006
			*!* MARIUS.MUTU
			*!* LA RETUR FACTURA FURNIZOR CANTITATE NEGATIVA, DACA E RETUR LA TOATA CANTITATEA DIN STOC,  
			*!* CANTITATEA TOTALA = 0, NUMERIC OVERFLOW LA CALCUL CMP
			*!* AM FACUT ABS(CANTE)
			SELECT SUM(ROUND(PRET*ABS(cante),gnPc)) AS valoare, SUM(ABS(cante)) AS cantitate, ID_ARTICOL, CONT ;
				FROM (tcRul) WITH (BUFFERING = .T.) ;
				WHERE cante <> 0 AND ID_ARTICOL = poArticol.ID_ARTICOL  AND CONT = poArticol.CONT ;
				GROUP BY ID_ARTICOL, CONT ;
				INTO CURSOR tCmp
		
		 
			SELECT tCmp
			SCAN
				SCATTER NAME ocmp
				&& pretul mediu ponderat
				lnCMP = ROUND(ocmp.valoare/ocmp.cantitate, gnPpret)
				
				&& articol, gestiune, cantitate_totala (cantitate achizitionata cu toate preturile + stoc)
				SELECT id_articol, id_gestiune, SUM(cante) AS cant ;
					FROM (tcRul) WITH (BUFFERING = .T.) ;
					WHERE ID_ARTICOL = ocmp.ID_ARTICOL AND cante <> 0 AND CONT = ocmp.CONT ;
					GROUP BY id_gestiune, ID_ARTICOL ;
					INTO CURSOR crsCantGest
		
				&& adaug in rulaj intrarea cu toata cantitatea (achizitionata + stoc) la noul pret mediu ponderat
				SELECT crsCantGest
				SCAN
					SCATTER NAME ocant
					SELECT (tcRul)
					APPEND BLANK
					GATHER NAME orul
					REPLACE PRET WITH lnCMP, cant WITH 0, cante WITH 0, tva WITH 0
					GATHER NAME ocant
					REPLACE nnir WITH lnNnir
					REPLACE id_tip_rulaj WITH 2 && RULAJ ARTIFICIAL CMP
					SELECT crsCantGest
				ENDSCAN
				USE IN crsCantGest
				
				&& diferente de pret din rotunjiri
				IF ROUND(lnCMP * ocmp.cantitate, gnPc) - ocmp.valoare <> 0
					SELECT (tcAct)
					APPEND BLANK
					GATHER NAME poact
					REPLACE nnir WITH lnNnir
					REPLACE scd WITH ocmp.CONT, scc WITH IIF(LEFT(ocmp.cont,3) = '371', '378', '308'), ascd WITH '', ascc WITH ''
					REPLACE suma WITH ROUND(lnCMP*ocmp.cantitate,gnPc) - ocmp.valoare		
				ENDIF
				
				SELECT tCmp
			ENDSCAN
			
			USE IN tCmp
		ENDSCAN && 	crsArticoleTemp
		USE IN crsArticoleTemp
		
		SELECT (tcRul)
		
		&& program vechi
		
		*!*	PARAMETERS tcRul, tcAct
		
		*!*	*** alocare numar NIR pt rulajele generate de CMP
		
		*!*		*** dezaloc in caz ca trece de mai multe ori prin metoda asta
		*!*	IF thisform.numar_plaja1.id_numar # 0
		*!*		thisform.numar_plaja1.dezalocare_numar()
		*!*	ENDIF 
		
		*!*	lnIdEnt = 0
		*!*	this.numar_plaja1.id_entitate = lnIdEnt
		*!*	this.numar_plaja1.tip = 4 && NIR PT CMP
		*!*	this.numar_plaja1.serie = 2 && Asa transmit paramerii la procedura viz_config_serii din oproceduri_configurare.prg
		*!*	this.numar_plaja1.alocare_numar()
		*!*	lnNnir = this.numar_plaja1.numar_curent 
		*!*	*** 
		
		*!*	SELECT * FROM (tcRul) WITH (BUFFERING = .T.) INTO CURSOR crsTempRul
		*!*	SELECT crsTempRul
		*!*	SCAN FOR cant <> 0
		*!*		SCATTER NAME orul
		*!*		lcCont = ALLTRIM(orul.cont)
		*!*		lcsql = [SELECT cants+cant-cante as cante, pret, id_articol, id_gestiune, id_gestiune as id_gestout, cont, acont FROM stoc where an = ?gnAn and luna = ?gnluna and id_articol = ?orul.id_articol and (cants+cant-cante)<>0 and TRIM(cont) =?lcCont]
		*!*		lcCursor = [tmpVer]
		*!*		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		*!*		If lnSucces < 0
		*!*			amessagebox(goExecutor.cEroare,0+16,"Eroare")
		*!*			Return
		*!*		ENDIF
		*!*		IF RECCOUNT(lcCursor) > 0
		*!*			SELECT (tcRul)
		*!*			APPEND BLANK 
		*!*			GATHER NAME orul
		*!*			REPLACE cante WITH orul.cant, cant WITH 0, nnir WITH lnNnir
		*!*		ENDIF 
		*!*		SELECT (lcCursor)
		*!*		SCAN 
		*!*			SCATTER NAME ointr
		*!*			SELECT (tcRul)
		*!*			APPEND BLANK 
		*!*			GATHER NAME orul
		*!*			REPLACE cant WITH 0, cante WITH 0
		*!*			GATHER NAME ointr
		*!*			REPLACE nnir WITH lnNnir
		*!*			SELECT (lcCursor)
		*!*		ENDSCAN 
		*!*		USE IN (lcCursor)
		*!*		
		*!*	*!*		SELECT (tcRul)
		*!*	*!*		LOCATE 
		
		*!*		&& aflu pretul mediu ponderat
		*!*		SELECT SUM(ROUND(pret*cante,gnPc)) as valoare, SUM(cante) as cantitate, id_articol, cont ;
		*!*			FROM (tcRul) WITH (BUFFERING = .T.) ;
		*!*			WHERE cante <> 0 AND id_articol = orul.id_articol ;
		*!*			GROUP BY id_articol, cont ;
		*!*			INTO CURSOR tCmp
		*!*			
		*!*		SELECT tCmp
		*!*		SCAN 
		*!*			SCATTER NAME ocmp
		*!*			lnCMP = ROUND(ocmp.valoare/ocmp.cantitate,gnPc)
		*!*			
		*!*			SELECT id_gestiune, SUM(cante) as cant FROM (tcRul) WITH (BUFFERING = .T.) ;
		*!*			WHERE id_articol = ocmp.id_articol AND cante <> 0 AND cont = ocmp.cont ;
		*!*			GROUP BY id_gestiune, id_articol ;
		*!*			INTO CURSOR crsCantGest
		*!*			
		*!*			SELECT crsCantGest 
		*!*			SCAN 
		*!*				SCATTER NAME ocant
		*!*				SELECT (tcRul)
		*!*				APPEND BLANK
		*!*				GATHER NAME orul
		*!*				REPLACE pret WITH lnCMP, cant WITH 0, cante WITH 0
		*!*				GATHER NAME ocant
		*!*				REPLACE nnir WITH lnNnir
		*!*				SELECT crsCantGest 
		*!*			ENDSCAN 
		*!*			USE IN crsCantGest 
		*!*			IF ROUND(lnCMP*ocmp.cantitate,gnPc) - ocmp.valoare <> 0
		*!*				SELECT (tcAct)
		*!*				APPEND BLANK
		*!*				GATHER NAME poact
		*!*				REPLACE nnir WITH lnNnir
		*!*				REPLACE scd WITH ocmp.cont, scc WITH '308 ', ascd WITH '', ascc WITH ''
		*!*				REPLACE suma WITH ROUND(lnCMP*ocmp.cantitate,gnPc) - ocmp.valoare
		*!*			ENDIF 
		*!*			SELECT tCmp
		*!*		ENDSCAN 
		*!*		USE IN tCmp
		*!*		SELECT crsTempRul
		*!*	ENDSCAN 
		*!*	USE IN crsTempRul
		
		*!*	SELECT (tcRul)
	ENDPROC

	PROCEDURE assign_analitic
		PARAMETERS tcCont,pcAct,pcRul
		
		PRIVATE pcCont,pcAct,pcRul,pParamP,pParamS
		STORE 0 TO pParamP,pParamS
		lcAnalitic = ''
		lcAlias = ALIAS()
		
		pcCont = ALLTRIM(tcCont)
		
		lcSel = [SELECT * from ] + gcs + [.config_analitice WHERE cont = '] + ALLTRIM(pcCont) + [']
		lcCursor = 'crs_cfg_ana'
		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		IF lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
		ENDIF 
		
		IF lnSucces > 0
			IF RECCOUNT('crs_cfg_ana')=0
				USE IN crs_cfg_ana
				lnSucces = -1
			ENDIF 
		ENDIF 
		
		IF lnSucces > 0
			SELECT crs_cfg_ana
			SCATTER NAME ocfg
			lcCampPrefix = NVL(ALLTRIM(ocfg.camp_leg_prefix),'')
			lcCampSufix = NVL(ALLTRIM(ocfg.camp_leg_sufix),'')
			
			IF !EMPTY(lcCampPrefix)
				IF TYPE('&pcRul..'+lcCampPrefix) # 'U'
					pParamP = &pcRul..&lcCampPrefix
				ELSE 
					IF TYPE('&pcAct..'+lcCampPrefix) # 'U'
						pParamP = &pcAct..&lcCampPrefix
					ENDIF 
				ENDIF 
			ENDIF 
			
			IF !EMPTY(lcCampSufix)
				IF TYPE('&pcRul..'+lcCampSufix) # 'U'
					pParamS = &pcRul..&lcCampSufix 
				ELSE 
					IF TYPE('&pcAct..'+lcCampSufix) # 'U'
						pParamS = &pcAct..&lcCampSufix 
					ENDIF 
				ENDIF 
			ENDIF 
		
			lcSel = [{call fconturi_analitice('] + ALLTRIM(gcs) + [','] + ALLTRIM(pcCont) + [',0,] + TRANSFORM(pParamP) + [,] + TRANSFORM(pParamS) + [)}]
			lcCursor = 'crs_analitice'
			lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			ENDIF 
		ENDIF 
		
		&& iau Primul Simbol Analitic din Tabel - ordonat pt ca e selectat cu Distinct
		IF lnSucces > 0
			SELECT crs_analitice
			GO top
			lcAnalitic = ALLTRIM(acont)
		ENDIF 
		
		&& verificare analiticului cu Planul de Conturi
		IF lnSucces > 0
			lcSel = [SELECT cont,acont from ] + gcs + [.vplcont_analitic WHERE cont = '] + ALLTRIM(pcCont) + [' and acont = '] + ALLTRIM(lcAnalitic) +  [' and an = ] + TRANSFORM(gnAn)
			lcCursor = 'crs_verific'
			lnSucces = goExecutor.oExecute(lcSel,lcCursor)
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			ENDIF 
		ENDIF 
		
		IF lnSucces > 0
			IF RECCOUNT('crs_verific')=0
				lnSucces = -1
			ENDIF 
		ENDIF 
		
		IF USED('crs_cfg_ana')
			USE IN crs_cfg_ana
		ENDIF 
		IF USED('crs_verific')
			USE IN crs_verific
		ENDIF 
		IF USED('crs_analitice')
			USE IN crs_analitice
		ENDIF 
		IF USED('crs_verific')
			USE IN crs_verific
		ENDIF 
		
		IF lnSucces < 0
			lcAnalitic = ''
		ENDIF 
		
		SELECT (lcAlias)
		RETURN lcAnalitic
		
	ENDPROC

	PROCEDURE assign_values
		PARAMETERS tcObjDestinatie, tcObjSursa1, tcObjSursa2
		
		lcSelRul = this.ct_grid_order1.cnumecursor 
		
		lcOdest = ALLTRIM(tcObjDestinatie)
		lcOsursa1 = ALLTRIM(tcObjSursa1)
		lcOsursa2 = ALLTRIM(tcObjSursa2)
		
		SELECT (lcSelRul)
		FOR i = 1 TO FCOUNT()
			lcNumeCol = FIELD(i)
			IF TYPE('&lcOsursa1..'+lcNumeCol) # 'U'
				&lcodest..&lcNumeCol = &lcosursa1..&lcNumeCol
			ENDIF 
			IF TYPE('&lcOsursa2..'+lcNumeCol) # 'U'
				IF EMPTY(&lcodest..&lcNumeCol)
					&lcodest..&lcNumeCol = &lcosursa2..&lcNumeCol
				ENDIF 
			ENDIF 
		ENDFOR 
		
		
		
		
		
		 
	ENDPROC

	PROCEDURE bon_fiscal
		PRIVATE pnSumaMp500
		
		pnSumaMp500 = thisform.ct_factura1.txTotal.Value 
		
		ocasamp500 = CREATEOBJECT('frm_tichete',pnSumaMp500)
		ocasamp500.show(1)
		RELEASE ocasamp500
		
	ENDPROC

	PROCEDURE calcul_pret_vanzare
		PARAMETERS tcTabel
		
		LOCAL lnPretv, lnTvav, lnCoefAdaos, lnSuma, lcTabel
		STORE 0 TO lnPretv, lnTvav, lnCoefAdaos, lnSuma
		
		IF EMPTY(tcTabel)
			lcTabel = this.ct_grid_order1.cnumecursor 
		ELSE 
			lcTabel = ALLTRIM(tcTabel)
		ENDIF 
		
		SELECT (lcTabel)
		SUM ROUND(ABS(cante*pret),gnPc) TO lnSuma
		
		IF lnSuma <> 0
			lnCoefAdaos = (pcobj.totftva-lnSuma)/lnSuma  && coeficientul mediu de adaos
		ELSE 
			lnCoefAdaos = 1
		ENDIF 
		
		SELECT (lcTabel)
		SET FILTER TO 
		REPLACE ALL proc_tvav WITH pcobj.proc_tva, procent WITH ROUND(lnCoefAdaos*100,2)
		CALCULATE cnt() TO lnRecords
		i = 0
		SCAN 
			i = i + 1
			REPLACE pretv WITH ROUND(pret + ROUND(pret*lnCoefAdaos,gnPPretV),gnPPretV)		&&	modificare 14.09.2007
			REPLACE tvav WITH ROUND(pretv*(proc_tvav-1),gnPPretV)
			lnPretv = lnPretv + ROUND(pretv*cante,gnPC)
			lnTvav = lnTvav + ROUND(tvav*cante,gnPC)
			IF i = lnRecords
				IF lnPretv # pcobj.totftva 
					REPLACE pretv WITH pretv + ROUND((pcobj.totftva - lnPretv)/cante,gnPPretV)
				ENDIF 
				IF lnTvav # pcobj.tottva
					REPLACE tvav WITH tvav + ROUND((pcobj.tottva - lnTvav)/cante,gnPPretV)
				ENDIF 
			ENDIF 
		ENDSCAN 
		
	ENDPROC

	PROCEDURE calcul_sume
		Parameters tcTabel
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		*!*		Model =-1 : Nota fara contabilizare
		*!*		Model = 1 : Nota simpla cu contabilizare
		*!*		Model = 2 : NIR
		*!*		Model = 3 : BON/FACTURA VANZARE
		*!*		Model = 4 : Retur BON/FACTURA VANZARE
		*!*		Model = 5 : Transfer
		*!*		Model = 6 : Retur Transfer
		*!*		Model = 7 : Diferenta de pret
		
		*!*		Param1 = 1 : En-detail
		*!*		Param1 = 2 : En-gros
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		
		*!* v 2.0.28 calculez valorile de achizitie in functie de gnTipGest
		*!* ACHIZITIE
		*!* !plNIRBONPretCuTVA : valoarea fara tva achizitie = cant*pret
		*!*				   : valoarea tva achizitie = valoarea fara tva achizitie * proc_tva
		*!*				   : valoarea cu tva achizitie = valoarea fara tva achizitie + valoarea tva achizitie
		*!*
		*!* plNIRBONPretCuTVA : valoarea tva achizitie = valoarea cu tva achizitie * (proc_tva - 1) / proc_tva
		*!*	BILETE RATC	   : valoarea fara tva achizitie = valoarea cu tva achizitie - valoarea tva achizitie
		*!*				   : valoarea cu tva achizitie = cant*(pret+tva)
		
		*!* VANZARE
		*!* gnTipGest <> 6 : valoarea fara tva vanzare = cant*pretv
		*!*				   : valoarea tva vanzare = valoarea fara tva vanzare * proc_tvav
		*!*				   : valoarea cu tva vanzare = valoarea fara tva vanzare + valoarea tva vanzare
		*!*				   : adaosul = valoarea fara tva vanzare - valoarea fara tva achizitie
		*!*
		*!* gnTipGest =  6 : valoarea fara tva vanzare = valorea cu tva vanzare - valoarea tva vanzare
		*!*				   : valoarea tva vanzare = valoarea cu tva vanzare * (proc_tvav-1)/proc_tvav
		*!*				   : valoarea cu tva vanzare = cant*(pretv+tvav)
		*!*				   : adaosul = valoarea fara tva vanzare - valoarea fara tva achizitie
		*!* v 2.0.28 ^
		Store 0 To lnTotBaza, lnTotTva, lnBazaDiscount, lnBazaAdaos, lnTvaDiscount, lnTvaAdaos
		
		If Pcount() = 0
			tcTabel = Alltrim(This.ct_grid_order1.cnumecursor)
		Endif
		
		*lcCant = [cant] + IIF(INLIST(oset.model, 3, 4),[e],[])  && 3 = bon, bon retur
		lcCant = This.osel_dr.cantitate
		llCalculFact = Iif(oset.param1 = 2, .F., .T.) && daca e En-gros (vanzare) nu mai recalculez Total factura
		
		If This.ct_discount1.Visible = .T.
			lnBazaDiscount = This.ct_discount1.baza_discount
			lnTvaDiscount = This.ct_discount1.tva_discount
		Endif
		
		If oset.adaos
			Do Case
				Case oset.param1 = 1 && factura de vanzare en-detail
					Select (tcTabel)
					Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal
		*!*	modificare ROAGEST v 2.0.94 : am adaugat conditia AND oset.id_set <> 75
					If !INLIST(gnTipGest, 6,7) AND oset.id_set <> 75
						Sum Round(pretv*&lcCant,gnPc) To lnTotBaza
						Sum Round(Round(pretv*&lcCant,gnPc)*(proc_tvav-1),gnPc) To lnTotTva
						lnBazaAdaos = lnTotBaza - Thisform.ntotal
					Else
						Sum Round(Round(pretv+tvav,gnPPretV)*&lcCant,gnPc) To lnTotctva
						Sum Round(Round((pretv+tvav)*&lcCant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) To lnTotTva
						lnTotBaza = lnTotctva - lnTotTva
						lnBazaAdaos = lnTotBaza - Thisform.ntotal
					Endif
		
					If oset.id_set = 75 && Transfer catre gestiune la pret de vanzare
		*!*	modificare ROAGEST v 2.0.94
		*!*					If gnTipGest <> 6
		*!*						*!*						Sum Round(tvav*&lcCant,gnPc) To lnTotTvav && nu stiu de ce pornea de la tvav unitar ???
		*!*						Sum Round(Round(pretv*&lcCant,gnPc)*(proc_tvav-1),gnPc) To lnTotTvav
		*!*					Else
							Sum Round(Round((pretv+tvav)*&lcCant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) To lnTotTvav
		*!*					Endif
		*!*	modificare ROAGEST v 2.0.94 ^
						Thisform.tx_totalctva.Value = lnTotTvav + lnTotBaza
					Endif
		
				Case oset.param1 = 2 && factura de vanzare en-gros
					This.ct_factura1.totctva = pcobj.totctva
					This.ct_factura1.totftva = pcobj.totftva
					This.ct_factura1.tva = pcobj.tottva
		
					Select (tcTabel)
					If !plNIRBONPretCuTVA
						Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal
					Else 
						Sum Round(&lcCant*(Pret+Tva),gnPc) - Round(Round(&lcCant*(Pret+Tva),gnPc)*(proc_tva - 1)/proc_tva, gnPC) To Thisform.ntotal
					EndIf 	
		
					lnTotBaza = This.ntotal
					lnBazaAdaos = This.ct_factura1.totftva - Thisform.ntotal
					This.ct_adaos1.baza_adaos = lnBazaAdaos
					
				Otherwise && NIR MARFA LA PRET DE VANZARE
					Select (tcTabel)
		
					If !plNIRBONPretCuTVA
						Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal
						Sum Round(Round(&lcCant*Pret,gnPc) * (proc_tva-1),gnPc) To lnTotTva
					Else
						Sum Round(&lcCant*(Pret+Tva),gnPc) - Round(Round(&lcCant*(Pret+Tva),gnPc)*(proc_tva - 1)/proc_tva, gnPC) To Thisform.ntotal
						Sum Round(Round(&lcCant*(Pret+Tva),gnPc)*(proc_tva - 1)/proc_tva, gnPC) To lnTotTva
					Endif
					lnTotBaza = This.ntotal
		
					If gnTipGest <> 6
						Sum Round(&lcCant*pretv, gnPc) - m.lnTotBaza To lnBazaAdaos
					Else
						Sum Round(Round(pretv+tvav,gnPPretV)*&lcCant,gnPc) To lnTotctvaOther
						Sum Round(Round((pretv+tvav)*&lcCant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) To lnTotTvaOther
						lnTotfTvaOhter = m.lnTotctvaOther - m.lnTotTvaOther
						lnBazaAdaos = m.lnTotfTvaOhter - m.lnTotBaza
					Endif
			Endcase
			Select (tcTabel)
			Sum procent To lnProcent
			Calculate Cnt() To lnNrRecord
			lnProcent = lnProcent/lnNrRecord
		
			This.ct_adaos1.baza_adaos = lnBazaAdaos
			This.ct_adaos1.proc_adaos = lnProcent
		Else
			Select (tcTabel)
			If !plNIRBONPretCuTVA
				Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal	
				Sum Round(Round(&lcCant*Pret,gnPc) * (proc_tva-1),gnPc) To lnTotTva
			Else 
				Sum Round(&lcCant*(Pret+Tva),gnPc) - Round(Round(&lcCant*(Pret+Tva),gnPc)*(proc_tva - 1)/proc_tva, gnPC) To Thisform.ntotal		
				Sum Round(Round(&lcCant*(Pret+Tva),gnPc)*(proc_tva - 1)/proc_tva, gnPC) To lnTotTva
			EndIf 
			lnTotBaza = Thisform.ntotal
		Endif
		
		
		If oset.factura And llCalculFact
			If oset.cursval
				Select (tcTabel)
				If gnTipGest <> 6 && calculez valftva si valtva pornind de la pretv in loc de (pretv+tvav)
					Sum Round(&lcCant*pretvval,gnPc),Round(Round(&lcCant*pretvval,gnPc)*(proc_tvav-1),gnPc) To lnTotalFTvaVal,lnTotalTvaVal
				Else
					Sum Round(Round(pretvval*proc_tvav,gnPVal)*&lcCant,gnPVal) To lnTotalCTvaVal
					Sum Round(Round(Round(pretvval*proc_tvav,gnPVal)*&lcCant,gnPVal)*(proc_tvav-1),gnPVal) To lnTotalTvaVal
					lnTotalFTvaVal = m.lnTotalCTvaVal - m.lnTotalTvaVal
				Endif
				With Thisform.ct_factura2
					.totftva = lnTotalFTvaVal
					.tva = lnTotalTvaVal
					.totctva = lnTotalFTvaVal + lnTotalTvaVal
					.Refresh()
				Endwith
				lnTotBaza = Round(lnTotalFTvaVal * poAct.Curs,gnPc)
				lnTotTva = Round(lnTotalTvaVal * poAct.Curs,gnPc)
			Endif
		
			With This.ct_factura1
				If oset.model = 2 && NIR
					lnBazaAdaos = 0
					lnTvaAdaos = 0
				Endif
				.totftva = lnTotBaza - lnBazaDiscount
				.tva = lnTotTva - lnTvaDiscount
				.totctva = .totftva + .tva
			Endwith
		Endif
		
		*!*	modificare	v 2.0.6
		Do Case
			Case oset.id_set = 216 && Intrare din transfer de la gest. valorica la pret de vanz.
				Select (tcTabel)
				If gnTipGest <> 6 && calculez valftva si valtva pornind de la pretv in loc de (pretv+tvav)
					Sum Round(pretv*cant,gnPc) To lnTotBaza216
					Sum Round(Round(pretv*cant,gnPc)*(proc_tvav-1), gnPc) To lnTotTvav
				Else
					Sum Round(Round(pretv+tvav,gnPc)*&lcCant,gnPc) To lnTotctva216
					Sum Round(Round((pretv+tvav)*&lcCant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) To lnTotTvav
					lnTotBaza216 = lnTotctva216 - lnTotTvav
				Endif
		
				Thisform.tx_totalctva.Value = lnTotTvav + lnTotBaza216
		
			Case Inlist(oset.id_set, 230, 232, 233, 235, 261) && protocol, sponsorizare
				Select (tcTabel)
		*!*	modificare conditie if v 2.0.94 		
				If !INLIST(gnTipGest, 6,7) &&gnTipGest <> 6
		*!*	modificare conditie if v 2.0.94 ^		
					Sum Round(pretv*&lcCant,gnPc) + Round(Round(pretv*&lcCant,gnPc)*(proc_tvav-1),gnPc) To lnTotal230
				Else 
					Sum Round((pretv+tvav)*cante,gnPc) To lnTotal230
				EndIf 
				Thisform.tx_totalctva.Value = lnTotal230
		*!*	modificare	ROAFACTURARE v 2.2.20
			CASE oset.id_set = 267
				SELECT (tcTabel)
				If !INLIST(gnTipGest, 6,7)
					Sum Round(pretv*cant,gnPc) + Round(Round(pretv*cant,gnPc)*(proc_tvav-1),gnPc) To lnTotal230
				Else 
					Sum Round((pretv+tvav)*cant,gnPc) To lnTotal230
				EndIf 
				Thisform.tx_totalctva.Value = lnTotal230
		*!*	modificare	ROAFACTURARE v 2.2.20	^
		ENDCASE
		IF thisform.ntotal#0
		lnProcentDiscount=(thisform.ct_discount1.baza_discount/thisform.ntotal)*100
		ELSE
		lnProcentDiscount=0
		ENDIF
		
		if(thisform.ct_discount1.combogrid3.Value=2)
		thisform.ct_discount1.txProc_discount.Value=lnProcentDiscount
		ENDIF
		
		*!*	modificare	v 2.0.6	^
		
		This.txNir.Refresh
		This.ct_factura1.Refresh
		This.ct_factura2.Refresh
		This.ct_adaos1.Refresh
	ENDPROC

	PROCEDURE caut_gestiune
		PARAMETERS tnFel
		
		IF EMPTY(tnFel)
			tnFel = 0
		ENDIF 
		
		IF tnFel = 1 && pret vanzare
			lcCond = [nr_pag = 6]
		ELSE 
			lcCond = [nr_pag in (2,3,4,5)]
		ENDIF 
		
		pcselect = [select * from vnom_GESTIUNI]
		pcFiltruOrig = [inactiv = 0 and ] + lcCond
		pcfiltru = [1=2]
		pcschema = []
		pcorder = [NUME_gestiune]
		pccoloane = [nume_gestiune,cgest]
		pcTitlu = [Nume Gestiune Destinatie] 
		pcTitluColoane = [Gestiune,Indicativ]
		locauta = cauta_alfa(pcselect,pcfiltru,pcschema,pcorder,pccoloane,pcTitlu,pcTitluColoane,'',.F.,pcFiltruOrig)		&& 11.07.2007
			
		RETURN locauta
	ENDPROC

	PROCEDURE compensare
		*!* 24.08.2011
		*!* marius.mutu
		*!* suma platita = suma modificata de utilizator, nu suma calculata din rulaj
		
		*!* 30.08.2011
		*!* marius.mutu
		*!* suma platita = suma modificata de utilizator daca este diferita de 0, nu suma calculata din rulaj
		
		IF USED('xcont')
			SELECT xcont
			LOCATE FOR Pozitie # Fel_Cont AND Cu_Inregistrari = 1
			IF FOUND()
				pcContul = ALLTRIM(cont_part)
				pnIdPart = idPart
				pcNume = numepart
				pnFelCont = Fel_Cont
				pcDenumire = ALLTRIM(explic_cont)
		
				pcCond = [ an = ?gnAn and luna = ?gnluna]
		
				llval = .F. && Deocamdata e doar in lei
				IF llval
					pccond= pccond + [ and ABS(i.precvaldeb + i.valdebit - i.precvalcred - i.valcredit)>0 and i.id_valuta = ] + ALLTRIM(STR(&lcObj..id_valuta))
				ELSE
					pccond= pccond + [ and (i.precvaldeb + i.valdebit - i.precvalcred - i.valcredit = 0) ]
				ENDIF
		
		
		
				pcselect = ['select i.* FROM ] + gcs + [.Vireg_parteneri i where 2=2 ']
				pcfiltru = [ i.id_part = ?pnIdPart AND ABS(i.precdeb + i.debit - i.preccred - i.credit)<>0 AND i.cont = ?pcContul and ] + pcCond
				pcschema = ['']
				pcorder = ['']
		
				PRIVATE podateintrod
				STORE '' TO podateintrod
		
				gencursor('podateintrod','crs_actcv',pcselect,pcfiltru,[''],'')
		
				lcFis = 'actcv' + ALLTRIM(pcContul)
		
				IF USED(lcFis)
					USE IN &lcFis
				ENDIF
		
				IF pnFelCont = 0
					lcsel = [SELECT *, ACONT AS ASCC, nume_val as numeval, curs as cursschimb, precdeb + debit as totctva, preccred+credit as achitat, ] +;
						[precvaldeb + valdebit AS sumaval, precVALcred+VALcredit as achitatval, ] +;
						[.f. as ales, 00000000000000.0000 as sumaachi, 000000000000.0000 as sumaachi2, 00000000000000.0000 as achilei, 00000000000000.0000 as difplus, 00000000000000.0000 as difminus, 000000.0000 as cursval, 000000.0000 as cursdif ] +;
						[FROM crs_actcv INTO CURSOR ] + lcFis + [ READWRITE ]
				ELSE
					lcsel = [SELECT *, ACONT AS ASCD, nume_val as numeval, curs as cursschimb, preccred + credit as totctva, precdeb+debit as achitat, ] + ;
						[precvalcred + valcredit as sumaval, precVALdeb+VALdebit as achitatval, ] + ;
						[.f. as ales, 00000000000000.0000 as sumaachi, 00000000000000.0000 as sumaachi2, 00000000000000.0000 as achilei, 00000000000000.0000 as difplus, 00000000000000.0000 as difminus, 000000.0000 as cursval, 000000.0000 as cursdif ] + ;
						[FROM crs_actcv INTO CURSOR ] + lcFis + [ READWRITE ]
				ENDIF
				&lcsel
		
				SELECT (lcFis)
		
				OPLATA=CREATEOBJECT('ocompensari')
				*		oplata.txtNume.value =lcNume
				OPLATA.titlufrumos1.CAPTION = pcDenumire + [: ] + pcNume
				OPLATA.pcFis = lcFis
				*!* 24.08.2011
		*!*			OPLATA.SUMA = THIS.ct_factura1.totctva
				OPLATA.SUMA = IIF(thisform.nfTotctva<> 0, thisform.nfTotctva, THIS.ct_factura1.totctva)
				*!* 24.08.2011 ^	
				OPLATA.pnFelCont = pnFelCont
				OPLATA.SHOW(1)
		
				*!*			SELECT (lcfis)
				*!*			CALCULATE cnt() FOR ales TO LnBife
				*!*			IF LnBife=1
				*!*				LOCATE FOR ALES
				*!*				&M=nract
				*!*			ELSE
				*!*				&M=0
				*!*			ENDIF
			ENDIF
		ENDIF 
	ENDPROC

	PROCEDURE do_adauga
		PRIVATE pnpretvtva
		pnpretvtva = 0
		PRIVATE poCote_tva
		STORE '' TO poCote_tva	
		
		
		local lnId
		lnId = 0
		llSucces = nom_articole_nou(@lnId)
		
		this.ct_grid_search1.actualizeaza_grid
	ENDPROC

	PROCEDURE do_modifica
		lcNomArt = this.ct_grid_search1.cnumecursor 
		SELECT (lcNomArt)
		SCATTER NAME lorec 	
		
		PRIVATE poCote_tva
		STORE '' TO poCote_tva
			
		lnId = lorec.id_articol	
		DO Adauga_Modifica_Inregistrare WITH [catalog_articole],lorec,lnId,[UPDATE]
		this.ct_grid_search1.actualizeaza_grid
	ENDPROC

	PROCEDURE do_sterge
		Local lnRecno, lcSelRul
		lcSelRul = This.ct_grid_order1.cnumecursor
		
		Select (lcSelRul)
		Scatter Name osterg		&&	modificare	ROAGEST v 2.1.19
		lnRecno = Recno()
		*!*	modificare	ROAGEST	v 2.1.19
		LOCATE FOR !DELETED()
		IF !FOUND()
			MESSAGEBOX("Nu exista inregistrari de sters!",48,"Atentie")
			RETURN
		ENDIF
		*!*	modificare	ROAGEST	v 2.1.25 : am adaugat conditia legata de oset.id_set ( ob. de inv. )
		If oset.model = 3 AND INLIST(gnFifoLifo,1,2) AND !INLIST(oset.id_set,70,72,104)
			Locate For id_articol = osterg.id_articol And id_gestout = osterg.id_gestout ;
				AND !DELETED() AND nrordine > osterg.nrordine
		*!*		And Nvl(serie,'') = Nvl(osterg.serie,'') AND Pret = osterg.Pret And Iif(Inlist(gnTipGest,6,7),pretv,1) = Iif(Inlist(gnTipGest,6,7),osterg.pretv,1)
			If Found()
				amessagebox("Nu puteti sterge acest articol deoarece nu se mai respecta metoda "+IIF(gnFifoLifo=1,"FIFO","LIFO")+" !",48,"Atentie")
				Go lnRecno
				RETURN
			Endif
		Endif
		Select (lcSelRul)
		GO lnRecno
		*!*	modificare	ROAGEST	v 2.1.19	^
		Delete
		
		*!* MODIFICAT 11.04.2006
		*!* MARIUS.MUTU - AM PUS RECNO('RUL_TEMP') IN CURSORUL DE TRANSFER - LA STERGERE SA POT STERGE SI LINIA CORESPONDENTA DIN CRSTRANSFER
		If Inlist(oset.model,5,6,7) And Used('crsTransfer')
			Select crsTransfer
			Goto lnRecno
			Delete
			This.ct_grid_order1.cb_tx_gestin.SetFocus()
		Endif
		This.ct_grid_order1.actualizeaza_grid
		This.calcul_sume
		*!*	modificare	ROAGEST v 2.1.19
		Select (lcSelRul)
		Go lnRecno
		If oset.model = 3
			SELECT (This.ct_grid_search1.cnumecursor)
			lnRecno = Recno()
			*!*	modificare ROAGEST v 2.1.25 : am inlocuit datain = osterg.datain cu cond. daca exista osterg.datain si coloana datain in this.ct_grid_search1.cnumecursor
			Locate For id_articol = osterg.id_articol And id_gestiune = osterg.id_gestout And Nvl(serie,'') = Nvl(osterg.serie,'') ;
				AND Pret = osterg.Pret And Iif(Inlist(gnTipGest,6,7),pretv,1) = Iif(Inlist(gnTipGest,6,7),osterg.pretv,1) ;
				AND IIF(INLIST(TYPE('osterg.datain'),'T','D') AND INLIST(TYPE(This.ct_grid_search1.cnumecursor+'.datain'),'T','D'),datain,datapif) = ;
				IIF(INLIST(TYPE('osterg.datain'),'T','D') AND INLIST(TYPE(This.ct_grid_search1.cnumecursor+'.datain'),'T','D'),osterg.datain,osterg.datapif)
			If Found()
				Replace stoc_actual With stoc_actual + osterg.cante
			Endif
			Go lnRecno
		Endif
		*!*	modificare	ROAGEST v 2.1.19	^
	ENDPROC

	PROCEDURE do_termin
		If This.inainte_de_do_termin()
			lcSelRul = This.ct_grid_order1.cnumecursor
			lcSelSt = This.ct_grid_search1.cnumecursor
			gnButon = 1
			pnButon = 1
			Buton = 1
			pnIesire = 1
			*this.Hide
		
			If Type('pnTipCasaMarcat') = 'U'
				pnTipCasaMarcat = 1
			Endif
			If Type('glListareBonFiscal')<>'U' And glListareBonFiscal And pnTipCasaMarcat#1
				lcStringmp500 = ''
				Thisform.bon_fiscal()
				If gnButon<>1
					Return
				Endif
			Endif
		
			Select actactan
			*!*	modificare ROAPRODUCTIE v 2.0.2
			*!*		If !Inlist(poact.id_set, 26001) && PV de productie
			llVerificare = verificare_note_contabile('actactan', .T.,.T., .F.)
			If !llVerificare
			*!*	modificare ROAPRODUCTIE v 2.0.2	^
				This.AlwaysOnTop = .F.
				Do Form verificare With .T.,.T.,3  && cu buton de precedent
				This.AlwaysOnTop = .T.
			Endif
			Do Case
				Case gnButon = 3
					*onirbon.visible = .t.
					Do nrord With lcSelRul
				Otherwise
					This.Release
			Endcase
		Endif
	ENDPROC

	PROCEDURE do_verifica_sume
		tcTabel = Alltrim(This.ct_grid_order1.cnumecursor)
		Select (tcTabel)
		Replace id_valuta_vanz With poAct.id_valuta_vanz All
		Calculate Sum(Round(pretvval*cante,gnPVal)),Sum(Round(pretv*cante,gnPc)) To lnTotalVal,lnTotalLei
		lnTotalVal = Round(lnTotalVal*poAct.Curs,gnPc)
		If lnTotalVal <> lnTotalLei
			lnDiferenta = lnTotalVal - lnTotalLei
			lnSemn = Sign(lnDiferenta)
		*!*		lnDiferenta = Abs(lnDiferenta)
			lnDiferenta = lnDiferenta
			lnDiferentaPretU = Exp((-1)*gnPPretV*Log(10))
			lnModificari = 1
		
			Do While lnModificari <> 0
				lnModificari = 0
				Select (tcTabel)
				Scan
					lnDiferentaPret = Round(lnDiferentaPretU*cante,gnPc)
					lnSemnPret = Sign(lnDiferentaPret)
					If Abs(lnDiferentaPret) <= Abs(lnDiferenta)
						lnDiferenta = lnDiferenta - lnSemn * lnDiferentaPret
						Replace pretv With pretv + lnSemn * lnSemnPret * lnDiferentaPretU
						lnModificari = lnModificari + 1
					Endif
				Endscan
			Enddo
		Endif
		
	ENDPROC

	PROCEDURE inainte_de_do_termin
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		*!*		Model =-1 : Nota fara contabilizare
		*!*		Model = 1 : Nota simpla cu contabilizare
		*!*		Model = 2 : NIR
		*!*		Model = 3 : BON/FACTURA VANZARE
		*!*		Model = 4 : Retur BON/FACTURA VANZARE
		*!*		Model = 5 : Transfer
		*!*		Model = 6 : Retur Transfer
		*!*		Model = 7 : Diferenta de pret
		
		*!*		Param1 = 1 : En-detail
		*!*		Param1 = 2 : En-gros
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		
		*!* v 2.0.28 calculez valorile de achizitie in functie de gnTipGest
		*!* ACHIZITIE
		*!* !plNIRBONPretCuTVA : valoarea fara tva achizitie = cant*pret
		*!*				   : valoarea tva achizitie = valoarea fara tva achizitie * proc_tva
		*!*				   : valoarea cu tva achizitie = valoarea fara tva achizitie + valoarea tva achizitie
		*!*
		*!* plNIRBONPretCuTVA : valoarea tva achizitie = valoarea cu tva achizitie * (proc_tva - 1) / proc_tva
		*!*	BILETE RATC	   : valoarea fara tva achizitie = valoarea cu tva achizitie - valoarea tva achizitie
		*!*				   : valoarea cu tva achizitie = cant*(pret+tva)
		
		*!* VANZARE
		*!* gnTipGest <> 6 : valoarea fara tva vanzare = cant*pretv
		*!*				   : valoarea tva vanzare = valoarea fara tva vanzare * proc_tvav
		*!*				   : valoarea cu tva vanzare = valoarea fara tva vanzare + valoarea tva vanzare
		*!*				   : adaosul = valoarea fara tva vanzare - valoarea fara tva achizitie
		*!*
		*!* gnTipGest =  6 : valoarea fara tva vanzare = valorea cu tva vanzare - valoarea tva vanzare
		*!*				   : valoarea tva vanzare = valoarea cu tva vanzare * (proc_tvav-1)/proc_tvav
		*!*				   : valoarea cu tva vanzare = cant*(pretv+tvav)
		*!*				   : adaosul = valoarea fara tva vanzare - valoarea fara tva achizitie
		*!* v 2.0.28 ^
		
		***-----------------------------------
		*!* Ordinea coloanelor in tabelul din stanga
		*!* salvata pe server in optiuni_util, varname = 'GEST_SELECTII' - pt. fiecare utilizator - pt. operatiile in care a intrat
		
		*!* 19.02.2010
		*!* marius.mutu
		*!* id_set 264, 265 finalizare aprovizionare din 3xx = 401 => 3xx = 32x din coresp_cont_venchelt.cont_aprovizionare
		
		*!* 06.09.2011
		*!* marius.mutu
		*!*	pnTotalFactura,pnBazaFactura,pnTvaFactura = valorile modificate de utilizator
		
		*!*	05.02.2014
		*!*	marius.mutu
		*!*	diferente baza, tva la NIR - x = 401; x se completeaza cu CORESP_CONT_VENCHELT.cont_diferente daca este completat, altfel 6588
		*!* #4132
		
		*!* 12.07.2016
		*!* marius.mutu
		*!* nu se mai inlocuieste scd cu 4426 pentru tva ach. neex. in cazul in care scc = 408. Trebuie sa ramana 4428 = 408
		
		*!* 23.01.2017
		*!* marius.mutu
		*!* vanzare produse en-detail (firma TVA Incasare) nu se schimba contul 4111 = 4428 in 4111 = 4427 19%
		
		*!* 28.11.2018
		*!* marius.mutu
		*!* Achizitii din CE, modific 4426 = 401 in 4426 = 4427
		
		*!* 12.11.2019
		*!* marius.mutu
		*!* id_set = 267 EDUARD AVIZ RETUR CLIENTI CUSTODIE VALORIC - am corectat valoarea 357 si tva vanzare 
		*!* daca era impartita pe mai multe gestiuni, sectii nu se completa corect
		
		*!*	modificare ROAPRODUCTIE v 2.0.2
		If Reccount(This.ct_grid_order1.cnumecursor) = 0
			amessagebox("Nu ati ales articolele!",48,"Atentie")
			Return .F.
		Endif
		*!*	modificare ROAPRODUCTIE v 2.0.2	^
		Local lnNrCols, lcHeader, lcHeader2, lcTitlu_col, lcControlSource, lcControlSource2, lcNume_col, lcOrdine, lcWidth_col, lcSql, lnPornire
		Store 0 To lnNrCols
		Store 1 To lnPornire
		Store '' To lcHeader, lcHeader2, lcTitlu_col, lcControlSource, lcControlSource2, lcNume_col, lcWidth_col, lcOrdine
		
		Create Cursor crsGrid (ordine N(3), ctrSource C(100), titlu C(100), width_col C(100))
		
		lnNrCols = This.ct_GRID_SEARCH1._GRID1.ColumnCount
		llNrOrd = This.ct_GRID_SEARCH1.lNumerotare
		lnPornire = Val(This.ct_GRID_SEARCH1.cb_tx_cautare1.criteriu.Value)
		
		For I=1 To lnNrCols
			If llNrOrd And I<>1 && ce se intampla daca nu e llNrOrd ??????
				lcColOrd = [this.ct_grid_search1._grID1.column] + Alltrim(Str(I))+[.columnorder]
				lnColOrd = &lcColOrd
		
		*!*	modificare	v 2.1.19
		*!*			lcHeader = [this.ct_grid_search1._grid1.column] + Alltrim(Str(I))+ [.grh]+Alltrim(Str(I))+[.]+[Caption]
				lcHeader = [This.ct_grid_search1._GRID1.column] + Alltrim(Str(I)) + [.grh] +Alltrim(Str(I))
				IF TYPE(lcHeader) = 'O'
					lcHeader = lcHeader + [.Caption]
				ELSE
					*!*	daca nu se poate ordona dupa coloana respectiva, atunci am Header1 in loc de grhI
					lcHeader = [This.ct_grid_search1._GRID1.column] + Alltrim(Str(I)) + [.header1.Caption]
				endif
		*!*	modificare	v 2.1.19	^
				lcHeader2 = &lcHeader
		
				lcControlSource = [this.ct_grid_search1._grid1.column] + Alltrim(Str(I))+ [.ControlSource]
				lcControlSource2 = &lcControlSource
		
				lcWidthColumn = [this.ct_grid_search1._grid1.column] + Alltrim(Str(I))+ [.width]
				lcWidthColumn2 = Alltrim(Str(&lcWidthColumn))
		
				Insert Into crsGrid (ordine, titlu, ctrSource, width_col) Values (lnColOrd, lcHeader2, lcControlSource2, lcWidthColumn2)
			Endif
		Endfor
		
		
		Select * From crsGrid Order By ordine Into Cursor crsGridOrd
		Use In crsGrid
		
		Select crsGridOrd
		Scan
			lcTitlu_col = lcTitlu_col + Alltrim(titlu) + ","
			lcNume_col = lcNume_col + Alltrim(ctrSource) + ";"
			lcWidth_col = lcWidth_col + Alltrim(width_col)+ ";"
		
			Select crsGridOrd
		Endscan
		
		
		lcTitlu_col = Substr(lcTitlu_col,1,Len(lcTitlu_col)-1)
		lcNume_col = Substr(lcNume_col,1,Len(lcNume_col)-1)
		lcWidth_col = Substr(lcWidth_col,1,Len(lcWidth_col)-1)
		
		lcOrd = [this.ct_grid_search1.corder]
		lcOrdine = &lcOrd
		
		*!* v 2.0.87 - gestselectii - coloane ordonate din optiuni utilizator
		lnid_sel = oSet.id_selSt
		
		If Type('crsGestSelectiiUtilizator.pornire')='U' && ver. 2.0.90
			Alter Table crsGestSelectiiUtilizator Add Column pornire N(2)
		Endif
		
		Select crsGestSelectiiUtilizator
		Locate For id_sel = oSet.id_selSt
		If Found()
			Update crsGestSelectiiUtilizator ;
				Set titlu_col = lcTitlu_col, nume_col = lcNume_col, ordine = lcOrdine, width_col = lcWidth_col, pornire = lnPornire ;
				WHERE id_sel = oSet.id_selSt
		Else
			Insert Into crsGestSelectiiUtilizator (id_sel, titlu_col, nume_col, ordine, width_col, pornire) ;
				VALUES (oSet.id_selSt, lcTitlu_col, lcNume_col, lcOrdine, lcWidth_col, lnPornire )
		Endif
		
		lcCursorXML = ''
		Cursortoxml("crsGestSelectiiUtilizator", "lcCursorXML", 2, 0+2+8, 0, "1")
		
		scrie_optiune_utilizator("GEST_SELECTII", lcCursorXML, "Ordinea coloanelor in tabelul din stanga in formularele de nir, bon, etc.")
		*!* v 2.0.87 - gestselectii ^
		***-----------------------------------
		
		
		Private poRec
		poRec = Null
		Local loRec
		Local lcSelRul, lcSelRulGr,lcContTr, lcAcontTr, lcRul, lcCursor, lnSucces, llSucces, lcCant, lnIdGestiuneTr
		
		Store '' To lcContTr, lcAcontTr
		lnIdGestiuneTr = 0
		lcSelRulGr = This.ct_grid_order1.cnumecursor
		Local lnRecno
		lnRecno = 0
		pnBazaV341       	= 0
		pnBazaV346       	= 0
		pnBazaVProd       	= 0
		pnBazaVAmb 			= 0
		pnBazaVal341       	= 0
		pnBazaVal346       	= 0
		pnBazaValProd       = 0
		pnBazaValAmb 		= 0
		*!* 15.03.2007
		Local llY
		llY = .F.
		*!* 15.03.2007 ^
		
		*!*	modificare facturare in valuta 24.09.2007
		If oSet.cursval
			Thisform.do_verifica_sume()
		Endif
		*!*	modificare facturare in valuta 24.09.2007	^
		
		Thisform.compensare && PT 542 ; se completeaza actactanul in adunadate
		
		*** completez tabela ACTACTAN
		If Type('oitem') = 'O'
			If Pemstatus(oitem,'adunadate',5)
				oitem.adunadate()
				*!*	modificare	ROAGEST v 2.2.0 : repun conturile modificate in actbaza2007
				select actactan
				replace all scc with '4427' for inlist(id_jtva_coloana,22,24,26,30,32,38,42) and scc = '4428'
				replace all scd with '4426' for inlist(id_jtva_coloana,171,173,175,179,189,211,215) and scd = '4428' AND scc <> '408' && aviz 4428 = 408
				*!*	modificare	ROAGEST v 2.2.0		
			Endif
		Endif
		***
		If Used('rul_temp')
			Use In rul_temp
		ENDIF
		&& completez RUL_TEMP
		lcRul = Alltrim(This.osel_dr.cfrom)
		lcSql = [select v.*,0 as pretvval,0 as curs,0 as id_valuta_vanz,0 as id_jtva_coloana,0 as taxcode, v.id_gestiune as id_gestin, v.nume_gestiune as gestin, v.id_gestiune as id_gestout, v.nume_gestiune as gestout, 0 as nuInConturiX]
		
		&& VRUL_OBINV NU ARE CODMATF, LOT, ADATA_EXPIRARE SI NU SE MAI SALVEAZA LOT, ADATA_EXPIRARE IN RUL
		If 'obinv'$Lower(lcRul)
			lcSql = lcSql + [,rpad(' ',50,' ') as codmatf, rpad(' ',50,' ') as lot, to_date('') as adata_expirare, rpad(' ',50,' ') as serie_obinv]
		Endif
		lcSql = lcSql + [ from ] + lcRul + [ where 1=2]
		lcCursor = [rul_temp]
		llSucces = goExecutor.oExecuta(lcSql,lcCursor)
		If !m.llSucces
			Return .F.
		Endif
		
		Select rul_temp
		Append From Dbf(lcSelRulGr)
		lcSelRul = 'rul_temp'
		
		*!* v 2.0.39
		*!*	modificare	ROAGEST v 2.0.51
		*!*	If oset.id_set = 236 && retur din transfer de la gestiune valorica mf pv - aviz expeditie
		*!* 240 && retur din transfer de la gestiune valorica (cantitativ) mf pv - aviz expeditie
		*!* 241 = 236 la mf pret ach
		*!* 242 = 240 la mf pret ach
		If Inlist(oSet.id_set,236,238,239,240,241,242,255,256,259,260) && retur din transfer de la gestiune valorica mf pv - aviz expeditie
			*!*	modificare	ROAGEST v 2.0.51	^
			*!* il introduc ca NIR, dar vreau sa apara ca intrare din retur (cante < 0)
			Select rul_temp
			Scan
				Scatter Name loRec
				Replace cante With -loRec.cant, cant With 0, id_gestiunec With poAct.id_gestout, id_gestin With poAct.id_gestout, id_gestout With poAct.id_gestin, datain With loRec.dataout, dataout With {}
			Endscan
			Select ACTACTAN
			Replace id_gestin With poAct.id_gestout, id_gestout With poAct.id_gestin, id_partc With 0, partc With ""
		Endif
		*!*	modificare	ROAFACTURARE	v 2.0.96
		pnDisctV = 0
		pnTvaDiscV = 0
		IF oSet.id_set = 267
			lnProcDiscount = Iif(oset.discount And Thisform.ct_discount1.Combogrid3.Value=3,Thisform.ct_discount1.proc_discount ,0) / 100
			Select rul_temp
			Scan
				Scatter Name loRec
				Replace cante With -loRec.cant, cant With 0, id_gestiunec With poAct.id_gestout, id_gestin With poAct.id_gestout, id_gestout With poAct.id_gestin, datain With loRec.dataout, dataout With {},;
					discunitar WITH ROUND((loRec.pretv+loRec.tvav)*lnProcDiscount,gnPPretV)
			Endscan
			Calculate Sum(Round(discunitar * Abs(cante),gnPc)-Round(Round(discunitar * Abs(cante),gnPc) * (proc_tvav-1)/proc_tvav,gnPc)),;
				SUM(Round(Round(discunitar * Abs(cante),gnPc) * (proc_tvav-1)/proc_tvav,gnPc)) To pnDiscV,pnTvaDiscV
			Select ACTACTAN
			Replace id_gestin With poAct.id_gestout, id_gestout With poAct.id_gestin, id_partc With 0, partc With ""
		ENDIF
		*!*	modificare	ROAFACTURARE	v 2.0.96	^
		If Inlist(oSet.id_set, 215, 216, 237,257) && intrare din transfer de la gestiune valorica
			Replace All id_gestiunec With poAct.id_gestout, id_gestout With poAct.id_gestout
		Endif
		
		*!* v 2.0.39
		If oSet.productie
			Do Case
				Case Alltrim(Upper(oSet.formproduc))='FRM_ALEGE_PROD_CANT'
					Thisform.intrare_produs()
				Case Inlist(Alltrim(Upper(oSet.formproduc)),'FRM_ALEGE_SECTIE_COMANDA','FRM_ALEGE_SECTIE')
					Select ACTACTAN
					*!*		modificare 03.09.2007
					*!*			Replace id_sectie With pnId_sectie, sectie With pcSectie For Inlist(nr_nota,1,2,5)
					Replace id_sectie With 0, sectie With '' For Inlist(nr_nota,4)
			Endcase
		Endif
		
		*!* 15.03.2007
		*!* pentru intrare dintr-o gestiune tinuta doar valoric - trebuie contul
		*!* daca exista Y (trebuie sa aleaga contul de transfer)
		Select xscd As SCD, xscc As scc From XNOTE Where id_set = oSet.id_set ;
			AND (Inlist(Upper(Alltrim(xscd)),'Y') Or Inlist(Upper(Alltrim(xscc)),'Y'));
			INTO Cursor crsY
		If _Tally > 0 Or Inlist(oSet.model, 5, 6, 7)
			llY = .T.
		Endif
		Use In crsY
		*!* 15.03.2007 ^
		
		If Inlist(oSet.model, 5, 6, 7) && TRANSFER, RETUR TRANSFER
		
			Select (lcSelRul)
			lnRecno = Recno()
			If oSet.id_set = 211 && TRANSFER GESTIUNE OB INV IN FOLOSINTA PE PERSOANA CATRE O MAGAZIE OB INV IN FOLOSINTA
				Replace id_responsabil With 0, nresp With ''
			Endif
		
			If Used('crsTransfer')
				Append From Dbf('crsTransfer')
		
				If oSet.id_set = 210 && TRANSFER MAGAZIE OB INV IN FOLOSINTA CATRE O GESTIUNE OB INV IN FOLOSINTA PE PERSOANA
					Replace id_responsabil With 0, nresp With '' For Recno() > lnRecno
				Endif
		
				*!*	modificare 22.05.2007
				***	se modifica pretul de ach. pentru intrari
				If oSet.id_set = 218 && Diferenta pret la produse
					Replace Pret With pretv For cant <> 0
				Endif
				*!*	modificare 22.05.2007 ^
			Endif
		
			If !Inlist(oSet.id_set,89, 210, 211, 212)  && (FARA TRANSFER INTRE PERSOANE)
				*!*			If Inlist(oset.id_seldr,11,16,18) && achizitie
				*!*				poGestTr = This.caut_gestiune()
				*!*			Endif
				*!*			If oset.id_seldr = 12 && vanzare
				*!*				poGestTr = This.caut_gestiune(1)
				*!*			Endif
				*!*			If Empty(poGestTr.Id_gestiune)  && renunt
				*!*				Return .F.
				*!*			Endif
		
				*!*			&& Dc poGestTr.Id_gestiune nu e empty aleg contul de transfer si analiticul
		
				*!*			loCont = This.aleg_cont_transfer(poGestTr.Id_gestiune)
		
				*!*			If Empty(loCont.Cont)	&& renunt
				*!*				Return .F.
				*!*			Endif
				&& oset.id_seldr = 12 : catre o gestiune de marfa la pret de vanzare
				loCauta = caut_gestiune_dest(0,Iif(oSet.id_seldr = 12, [6],[2,3,4,5]),0)
				If Nvl(loCauta.id_gestiune,0) = 0
					Return .F.
				Else
					poGestTr = Createobject("custom")
					poGestTr.AddProperty("id_gestiune", loCauta.id_gestiune)
					poGestTr.AddProperty("nume_gestiune", loCauta.nume_gestiune)
					loCont = Createobject("custom")
					loCont.AddProperty("cont", loCauta.Cont)
					loCont.AddProperty("acont", Nvl(loCauta.acont,""))
				Endif
		
		
				Select (lcSelRul)
				Replace All id_gestin With poGestTr.id_gestiune, gestin With poGestTr.nume_gestiune   &&FOR cant <> 0
				Do Case
					Case Inlist(oSet.model,5,7) && transfer
						Replace All id_gestiune With poGestTr.id_gestiune, nume_gestiune With poGestTr.nume_gestiune For cant <> 0
					Case oSet.model = 6 && retur
						Replace All id_gestiune With poGestTr.id_gestiune, nume_gestiune With poGestTr.nume_gestiune For cante <> 0
				Endcase
		
				lcContTr = loCont.Cont
				lcAcontTr = loCont.acont
		
				Select ACTACTAN
				Replace All SCD With lcContTr, ascd With lcAcontTr, id_gestin With poGestTr.id_gestiune, gestin With poGestTr.nume_gestiune For Upper(Alltrim(SCD)) = 'Y'
				Select (lcSelRul)
				If oSet.model = 6
					lcCant = Thisform.osel_dr.cantitate
				Else
					lcCant = [cant]
				Endif
				Replace All Cont With lcContTr, acont With lcAcontTr For &lcCant <> 0
				*!*			REPLACE ALL id_gestiunec WITH id_gestout FOR cant <> 0
				*!*			REPLACE ALL id_gestiunec WITH id_gestin FOR cante <> 0
				*!*			REPLACE ALL nuInConturiX WITH 1 FOR cant <> 0
			Endif
			Select (lcSelRul)
			Replace All id_gestiunec With id_gestout For cant <> 0
			Replace All id_gestiunec With id_gestin For cante <> 0
			Replace All nuInConturiX With 1 For cant <> 0
		Endif
		
		Select (lcSelRul)
		
		If oSet.param1 = 2 And oSet.factura  &&  factura en-gros
			This.calcul_pret_vanzare(lcSelRul)
			*!*	modificare 31.10.2006
			pnTotalFactura = This.ct_factura1.totctva
			pnBazaFactura = This.ct_factura1.totftva
			pnTvaFactura = This.ct_factura1.tva
		
			Select rul_temp
			If gnTipGest <> 6
				Calculate Sum(Round(Round(pretv,gnPPretV)*cante,gnPc)),;
					SUM(Round(Round(Round(pretv,gnPPretV)*cante,gnPc)*(proc_tvav-1),gnPc)) ;
					TO lnBazaFactura,lnTvaFactura
			Else
				Calculate Sum(Round(Round(pretv+tvav,gnPPretV)*cante,gnPc)) To lnTotFactura
				Calculate Sum(Round(Round(Round(pretv+tvav,gnPPretV)*cante,gnPc)*(proc_tvav-1)/proc_tvav,gnPc)) To lnTvaFactura
				lnBazaFactura = lnTotFactura - lnTvaFactura
			Endif
		
			Do Case
				Case lnBazaFactura <> pnBazaFactura And lnTvaFactura <> pnTvaFactura
					lcMesaj = [Diferenta intre sumele introduse si cele rezultate din calcul:] + CRLF + ;
						SPACE(23) + [Baza] + Space(18) + [TVA] + CRLF + ;
						[Introduse:] + Space(5) + Str(pnBazaFactura,20,gnPc) + [ ] + Str(pnTvaFactura,20,gnPc) + ;
						CRLF +;
						[Calculate:] + Space(5) + Str(lnBazaFactura,20,gnPc) + [ ] + Str(lnTvaFactura,20,gnPc) + ;
						CRLF + CRLF + ;
						[Doriti sa continuati?]
				Case lnBazaFactura <> pnBazaFactura
					lcMesaj = [Diferenta intre sumele introduse si cele rezultate din calcul:] + CRLF + ;
						SPACE(23) + [Baza] + CRLF + ;
						[Introduse:] + Space(5) + Str(pnBazaFactura,20,gnPc) + CRLF+;
						[Calculate:] + Space(5) + Str(lnBazaFactura,20,gnPc) + CRLF + CRLF + ;
						[Doriti sa continuati?]
				Case lnTvaFactura <> pnTvaFactura
					lcMesaj = [Diferenta intre sumele introduse si cele rezultate din calcul:] + CRLF + ;
						SPACE(24) + [TVA] + CRLF + ;
						[Introduse:] + Space(5) + Str(pnTvaFactura,20,gnPc) + CRLF +;
						[Calculate:] + Space(5) + Str(lnTvaFactura,20,gnPc) + CRLF + CRLF + ;
						[Doriti sa continuati?]
				Otherwise
					lcMesaj = []
			Endcase
		
			If !Empty(lcMesaj)
				If amessagebox(lcMesaj,4+32+256,"Confirmare")==7
					Return .F.
				Else
					pnBazaFactura = lnBazaFactura
					pnTvaFactura = lnTvaFactura
					pnTotalFactura = lnBazaFactura + lnTvaFactura
				Endif
			Endif
		Else
		*!* 06.09.2011
		*!*		pnTotalFactura = This.ct_factura1.totctva
		*!*		pnBazaFactura = This.ct_factura1.totftva
		*!*		pnTvaFactura = This.ct_factura1.tva
			
			pnTotalFactura = IIF(thisform.nfTotctva<> 0, thisform.nfTotcTva, THIS.ct_factura1.totctva)
			pnBazaFactura = IIF(thisform.nfTotfTva <> 0, thisform.nfTotfTva, This.ct_factura1.totftva)
			pnTvaFactura = IIF(thisform.nfTotTva<> 0, thisform.nfTotTva, This.ct_factura1.tva)
			*!*	modificare 31.10.2006	^
		*!* 06.09.2011 ^
		Endif
		
		pnDiscount = This.ct_discount1.baza_discount
		pnTVADiscount = -This.ct_discount1.tva_discount
		pnProcDiscount = This.ct_discount1.pnTva
		pnIdJtvaDiscount = This.ct_discount1.nid_jtva_coloana
		pnIdTvaDiscount = This.ct_discount1.nid_tva
		
		*!*	pnTotalFactura = THIS.ct_factura1.totctva
		*!*	pnBazaFactura = THIS.ct_factura1.totftva
		*!*	pnTvaFactura = THIS.ct_factura1.tva
		
		
		pnBazaNir  = [pret*cant]
		pnBazaBon  = [pret*cante]
		pnTotalBon = This.ntotal
		pnTotalNir = This.ntotal
		
		lcCant = Lower(Alltrim(This.osel_dr.cantitate))
		*!* ROAGEST V 2.0.61
		*!*	modificare	ROAGEST v 2.0.53
		*!*	If Inlist(oset.model, 5, 6, 7)  && transfer
		*!* 236,240,241,242 - RETUR DE LA GESTIUNE VALORICA (-CANTE)
		*!* 267 retur valoric din custodie
		If Inlist(oSet.model, 5, 6, 7) Or Inlist(oSet.id_set,238,239,236,240,241,242,255,256,259,260,267 )
			lcCant = [cante]
		Endif
		*!*	modificare	ROAGEST v 2.0.53	^
		*!* ROAGEST V 2.0.61 ^
		
		If !plNIRBONPretCuTVA
			pcTvaNirFormula = [ROUND(ROUND(cant*pret,gnPc)*(proc_tva-1),gnPc)]
			pcBazaNirFormula = [Round(cant*pret,gnPc)]
			pcBazaBonFormula = [Round(cante*pret,gnPc)]
		Else
			pcTvaNirFormula = [Round(ROUND(cant*(pret+tva),gnPc) * (proc_tva-1)/proc_tva, gnPC)]
			pcBazaNirFormula = [Round(cant*(pret+tva),gnPc) - Round(ROUND(cant*(pret+tva),gnPc) * (proc_tva-1)/proc_tva, gnPC)]
			pcBazaBonFormula = [Round(cante*(pret+tva),gnPc) - Round(ROUND(cante*(pret+tva),gnPc) * (proc_tva-1)/proc_tva, gnPC)]
		Endif
		*!*	modificare ROAGEST v 2.0.94 : am adaugat conditia AND oset.id_set <> 75
		If !Inlist(gnTipGest, 6, 7) And oSet.id_set <> 75
			pnBazaVanz = [ROUND(pretv*cante,gnPc)]
			pnBazaVal = [ROUND(pretvval*cante,gnPVal)]
			pnBazaValVanz = [ROUND(ROUND(pretvval*curs,gnPPretV)*cante,gnPC)]
			pnTvaVanzOut2 = [Round(ROUND(pretv*cante,gnPc)*(proc_tvav-1),gnPc)] && PROTOCOL
			pnTvaVal = [ROUND(ROUND(pretvval*cante,gnPVal)*(proc_tvav-1),gnPVal)]
			pnTvaValVanz = [ROUND(ROUND(ROUND(pretvval*curs,gnPPretV)*cante,gnPC)*(proc_tvav-1),gnPC)]
			pcBazaVanzFormula = [ROUND(pretv*cante,gnPc)]
			pnTvaVanzIn = [Round(ROUND(pretv*cant,gnPc) * (proc_tvav-1), gnPC)]
			pnTvaVanzOut = [Round(ROUND(pretv*cante,gnPc) * (proc_tvav-1), gnPC)]
			If !plNIRBONPretCuTVA
				pnAdaos = [Round(] + lcCant+ [ * pretv, gnPc) - Round(] + lcCant+ [ * pret, gnPc)]
			Else
				pnAdaos = [Round(] + lcCant+ [ * pretv, gnPc) - (ROUND((pret+tva)*] + lcCant + [,gnPc) - Round(ROUND((pret+tva)*] + lcCant + [,gnPc) * (proc_tva-1)/proc_tva, gnPC))]
			Endif
			*!*	modificare ROAGEST v 2.0.45
			pnVanzOutCuTva = pnBazaVanz + [+] + pnTvaVanzOut
			*!*	modificare ROAGEST v 2.0.45	^
		Else
			pnBazaVanz = [ROUND((pretv+tvav)*cante,gnPc) - Round(ROUND((pretv+tvav)*cante,gnPc) * (proc_tvav-1)/proc_tvav, gnPc)]
			pnBazaVal = [ROUND(Round(pretvval*proc_tvav,gnPVal)*cante,gnPVal) - Round(ROUND(Round(pretvval*proc_tvav,gnPVal)*cante,gnPVal) * (proc_tvav-1)/proc_tvav, gnPVal)]
			pnBazaValVanz = [ROUND(Round(ROUND(pretvval*curs,gnPPretV)*proc_tvav,gnPPretV)*cante, gnPc) - Round(ROUND(Round(ROUND(pretvval*curs,gnPPretV)*proc_tvav, gnPPretV)*cante, gnPc) * (proc_tvav-1)/proc_tvav, gnPc)]
			pnTvaVanzOut2 = [Round(Round((pretv+tvav)*cante,gnPc)*(proc_tvav-1)/proc_tvav, gnPc)] && PROTOCOL
			pnTvaVal = [Round(ROUND(Round(pretvval*proc_tvav,gnPVal)*cante,gnPVal) * (proc_tvav-1)/proc_tvav, gnPVal)]
			pnTvaValVanz = [Round(ROUND(Round(ROUND(pretvval*curs,gnPPretV)*proc_tvav, gnPPretV)*cante, gnPc) * (proc_tvav-1)/proc_tvav, gnPc)]
			pcBazaVanzFormula = [ROUND((pretv+tvav)*cante,gnPc) - Round(ROUND((pretv+tvav)*cante,gnPc) * (proc_tvav-1)/proc_tvav, gnPC)]
			pnTvaVanzIn = [Round(ROUND((pretv+tvav)*cant,gnPc)* (proc_tvav-1)/proc_tvav, gnPC)]
			pnTvaVanzOut = [Round(ROUND((pretv+tvav)*cante,gnPc)* (proc_tvav-1)/proc_tvav, gnPC)]
			If !plNIRBONPretCuTVA
				pnAdaos = [ROUND((pretv+tvav)*] + lcCant + [,gnPc) - Round(ROUND((pretv+tvav)*] + lcCant + [,gnPc) * (proc_tvav-1)/proc_tvav, gnPC) - ] + ;
					[Round(] + lcCant+ [ * pret, gnPc)]
			Else
				pnAdaos = [ROUND((pretv+tvav)*] + lcCant + [,gnPc) - Round(ROUND((pretv+tvav)*] + lcCant + [,gnPc) * (proc_tvav-1)/proc_tvav, gnPC) - ] + ;
					[(ROUND((pret+tva)*] + lcCant + [,gnPc) - Round(ROUND((pret+tva)*] + lcCant + [,gnPc) * (proc_tva-1)/proc_tva, gnPC))]
			Endif
			*!*	modificare ROAGEST v 2.0.45
			pnVanzOutCuTva = [Round((pretv+tvav)*cante,gnPc)]
			*!*	modificare ROAGEST v 2.0.45	^
		Endif
		
		If oSet.id_set = 104 And gnImputare = 1
			pnBazaVanz = [ROUND(pret_imputare*cante,gnPc)]
			pnTvaVanzOut = [ROUND(ROUND(pret_imputare*cante,gnPc)*(proc_tvav-1),gnPc)]
		Endif
		
		pnAdaosTotal = This.ct_adaos1.baza_adaos
		pnBazaPlusAdaos = pnTotalBon + pnAdaosTotal
		
		Select * From XNOTE Where id_set = oSet.id_set Into Cursor crsNota
		lcField = ''
		Select xact
		Go Top
		
		For I = 1 To Fcount()
			If Upper(Alltrim(Evaluate(Field(I)))) = 'SUMA'
				lcField = Field(I)
				Exit
			Endif
		Endfor
		
		If Empty(lcField)
			Return .T.
		Endif
		
		Select Distinct xscd As SCD, xscc As scc, Padr(&lcField,100,' ') As eticheta,x34,x37 From crsNota ;
			WHERE Inlist(Upper(Alltrim(xscd)),'X') Or Inlist(Upper(Alltrim(xscc)),'X');
			INTO Cursor crsIcsi
		If _Tally > 0
			Select crsIcsi
			Scan
				lcEticheta = Lower(Alltrim(eticheta))
				If Empty(lcEticheta)
					amessagebox('NECONFIGURAT xnote.dbf !',48,'Atentie!')
					Loop
				Endif
				lcSCD = Upper(Alltrim(SCD))
				lcSCC = Upper(Alltrim(scc))
				lcIDJtva = Upper(Alltrim(x34)) && ID_JTAX/ID_TVA/pnIdJTvaDiscount/pnIdTvaDiscount
				lcTaxCode = UPPER(ALLTRIM(x37)) && STAXCODE
				If Inlist(oSet.model, 5, 6, 7) && TRANSFER, RETUR TRANSFER
					If lcSCD = 'Y'
						lcSCD = lcContTr
					Endif
					If lcSCC = 'Y'
						lcSCC = lcContTr
					Endif
				Endif
		
				&& despart sumele pe gestiuni si sectii - pt formarea corecta a analiticelor
				If 'pntvavanz' $ lcEticheta Or 'pnadaos' $ lcEticheta
		
					*!*				IF 'pnadaos'$lcEticheta
					If Type('&lcEticheta') <> 'N'
						lcEticheta =  &lcEticheta
					Endif
					lcSuma = [SUM(ROUND(&lcEticheta,gnPc))]
					*!*				ELSE
					*!*					lcEticheta =  &lcEticheta
					*!*					lcSuma = [SUM(ROUND(ROUND(&lcEticheta,gnPc)*(proc_tvav-1),gnPc))]
					*!*				ENDIF
		
					lcSelect = [SELECT CONT,ACONT,id_gestiune,id_sectie,sectie,id_lucrare,nrord,] + ;
						IIF(Type(lcSelRul+'.id_jtva_coloana')#'U',[id_jtva_coloana],[NULL]) + [ as id_jtva_coloana,] + ;
						IIF(Type(lcSelRul+'.taxcode')#'U',[taxcode],[NULL]) + [ as taxcode,] + ;				
						IIF(Type(lcSelRul+'.proc_tvav')#'U',[proc_tvav],[0000]) + [ as proc_tva,] +;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[id_gestin],[000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ AS suma ] + ;
						[FROM ] + lcSelRul + [ where nuInConturiX = 0 into cursor crsConturiX ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14]
					&lcSelect
				Else
					*!* v 2.0.24 valoarea baza achizitie = diferenta intre valoarea cu tva si valoarea tva
					Do Case
						Case 'pnbazanir' $ Lower(lcEticheta)
							lcSuma = [Sum(&pcBazaNirFormula)]
						Case 'pnbazabon' $ Lower(lcEticheta)
							lcSuma = [Sum(&pcBazaBonFormula)]
						Otherwise
							If Type('&lcEticheta') <> 'N'
								lcEticheta =  &lcEticheta
							Endif
		
							lcSuma = [SUM(ROUND(&lcEticheta,gnPc))]
					Endcase
					*!* v 2.0.24
					*!*				lcSuma = [SUM(ROUND(]+ALLTRIM(STR(lcEticheta,20,6))+[,gnPc))]
					lcSelect = [SELECT CONT,ACONT,id_gestiune,id_sectie,sectie,id_lucrare,nrord,] + ;
						IIF(Type(lcSelRul+'.id_jtva_coloana')#'U',[id_jtva_coloana],[NULL]) + [ as id_jtva_coloana,] + ;
						IIF(Type(lcSelRul+'.taxcode')#'U',[taxcode],[NULL]) + [ as taxcode,] + ;								
						IIF(Type(lcSelRul+'.proc_tva')#'U',[proc_tva],[0000]) + [ as proc_tva,] +;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[id_gestin],[000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ AS suma ] + ;
						[FROM ] + lcSelRul + [ where nuInConturiX = 0 into cursor crsConturiX ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14]
					&lcSelect
				Endif
		
				Select crsConturiX
		
				Scan For suma*0 = 0 && sa evit cazurile in care suma este ******
					Scatter Name loCX
		
					Select ACTACTAN
					Locate For Upper(Alltrim(SCD)) = lcSCD And Upper(Alltrim(scc)) = lcSCC
					If Found()
		
						Scatter Name loActactan
						With loActactan
							If Upper(Alltrim(.SCD)) = 'X'
								.SCD = loCX.Cont
								.ascd = Nvl(loCX.acont,'')
								.suma = loCX.suma
								If !Empty(lcIDJtva) && AND !INLIST(oset.model,5,6)
									.id_jtva_coloana = loCX.id_jtva_coloana
									.proc_tva = loCX.proc_tva
								Else
									.id_jtva_coloana = Null
									.proc_tva = 0
								Endif
								.taxcode = IIF(!Empty(m.lcTaxCode), loCX.taxcode, NULL)
								.id_gestin = loCX.id_gestin
								.gestin = loCX.gestin
								.id_gestout = loCX.id_gestout
								.gestout = loCX.gestout
								.id_sectie = loCX.id_sectie
								.sectie = loCX.sectie
								.id_lucrare = loCX.id_lucrare
								.nrord = loCX.nrord
							Endif
							If Upper(Alltrim(.scc)) = 'X'
								.scc = loCX.Cont
								.ascc = Nvl(loCX.acont,'')
								.suma = loCX.suma
								*!*	modificare 04.10.2007
								*!*								If Left(.scd,1) = '6' And Alltrim(.scd) # '607' And Inlist(oset.model, 3, 4) && BON, RETUR
								*!*									If .scc = '381'
								*!*										.scd = '608'
								*!*									Else
								*!*										.scd = Strtran(.scc, '3', '6', 1, 1)
								*!*									Endif
								*!*								Endif
								If Inlist(oSet.model,3,4)
									Select crsconfigcvc
									Locate For Cont = Upper(Alltrim(.scc))
									If Found() And (Empty(.SCD) Or Inlist(Left(.SCD,1), '6','7'))
										.SCD = Alltrim(cont_chelt)
									Else
										If Left(.SCD,1) = '6' And Alltrim(.SCD) # '607'
											IF LEFT(.scc,1) = '8' && clasa 8 nu are corespondent (obiecte inventar in folosinta)
												.scd = ''	
											Else
												If .scc = '381'
													.SCD = '608'
												ELSE 	
													.SCD = Strtran(.scc, '3', '6', 1, 1)
												ENDIF
											ENDIF 	
										Endif
									Endif
									Select ACTACTAN
								Endif
								*!*	modificare 04.10.2007	^
								If !Empty(lcIDJtva) && AND !INLIST(oset.model,5,6)
									.id_jtva_coloana = loCX.id_jtva_coloana
									.proc_tva = loCX.proc_tva
								Else
									.id_jtva_coloana = Null
									.proc_tva = 0
								ENDIF
								.taxcode = IIF(!Empty(m.lcTaxCode), loCX.taxcode, NULL)						
								.id_gestin = loCX.id_gestin
								.gestin = loCX.gestin
								.id_gestout = loCX.id_gestout
								.gestout = loCX.gestout
								.id_sectie = loCX.id_sectie
								.sectie = loCX.sectie
								.id_lucrare = loCX.id_lucrare
								.nrord = loCX.nrord
							Endif
						Endwith
						Append Blank
						Gather Name loActactan
					Endif && IF FOUND()
		
					Select crsConturiX
				Endscan
				Select crsIcsi
			Endscan
		
			Delete From ACTACTAN Where Inlist(Upper(Alltrim(SCD)),'X') Or Inlist(Upper(Alltrim(scc)),'X')
		Endif
		*!* 15.03.2007 ^
		*!* inlocuiesc Y - la notele care nu sunt transfer sau retur transfer (intrare dintr-o gestiune tinuta valoric - trebuie contul)
		If !Inlist(oSet.model, 5, 6, 7) And llY
			Select rul_temp
			Go Top
			lnIdGestiuneTr = id_gestiune
			If !Empty(lnIdGestiuneTr)
		
				loCont = This.aleg_cont_transfer(lnIdGestiuneTr)
				lcContTr = loCont.Cont
				lcAcontTr = loCont.acont
				Select ACTACTAN
		
				Replace All SCD With lcContTr, ascd With lcAcontTr For Upper(Alltrim(SCD)) = 'Y'
				Replace All scc With lcContTr, ascc With lcAcontTr For Upper(Alltrim(scc)) = 'Y'
		
			Endif
		
			*!* 20.03.2007
			*!* cont de transfer - cont din nomenclator
			*!* in rul aj trebuie sa am pe intrari contul din debit (contul de transfer)
			If oSet.model = 2 Or Upper(Alltrim(oSet.formgest)) = 'NIR'
				Select rul_temp
				Replace All Cont With lcContTr
			Endif
		Endif
		
		*!* 15.03.2007 ^
		Select crsNota
		Scan For !(Inlist(Upper(Alltrim(xscd)),'X') Or Inlist(Upper(Alltrim(xscc)),'X'))
			Scatter Name loNota
		
			lcVariabila = Lower(Alltrim(loNota.&lcField))
			lcIDJtva = Upper(Alltrim(x34))
			If Inlist(oSet.model, 5, 6, 7) Or llY && TRANSFER, RETUR TRANSFER
				If loNota.xscd = 'Y'
					loNota.xscd = lcContTr
					loNota.xAscd = lcAcontTr
				Endif
				If loNota.xscc = 'Y'
					loNota.xscc = lcContTr
					loNota.xAscc = lcAcontTr
				Endif
			Endif
						
			Do Case
				Case 'pntvanir' $ lcVariabila
					lcSuma = [SUM(&pcTvaNirFormula)]
					lcSelect = [SELECT b.id_tva as id_jtva_coloana,a.proc_tva,CAST(] + IIF(Type(lcSelRul+'.taxcode')#'U',[a.taxcode],[NULL]) + [ as I) as taxcode,a.id_sectie,a.id_gestiune,a.sectie,a.id_lucrare,a.nrord,] + ;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ as suma ] + ;
						[FROM ] + lcSelRul + [ a LEFT JOIN jtva_coloane b ON a.id_jtva_coloana = b.id_jtva_coloana ] + ;
						[INTO CURSOR crsTva ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12]
					*!* v 2.0.24 ^
					&lcSelect
		
					Select crsTva
					I  = 0
					Scan For suma*0 = 0 && sa evit cazurile in care suma este ******
						I = I + 1
						If I = 1
							Select ACTACTAN
							Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
							If Found()
								Scatter Name loAct
								Delete
							Else
								Scatter Name loAct Blank
							Endif
						Endif
						Select crsTva
						Scatter Name loTva
						Select ACTACTAN
						Append Blank
						Gather Name loAct
						Gather Name loTva
						If Empty(lcIDJtva)
							Replace id_jtva_coloana With Null,proc_tva With 0
						Endif
					Endscan
				Case 'pnbazavanz'$lcVariabila Or 'pntvavanz'$lcVariabila
					lcVariabilatemp = lcVariabila
		
					lcVariabila = &lcVariabila
					lcSuma = [sum(ROUND(&lcVariabila,gnPc))]
		
					DO CASE 
						CASE 'pnbazavanz'$lcVariabilatemp
							lcSuma = [Sum(&pcBazaVanzFormula)]
							lcSelect = [SELECT a.id_jtva_coloana,a.proc_tvav,a.taxcode,a.id_sectie,a.id_gestiune,a.sectie,a.id_lucrare,a.nrord,] + ;
								IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
								IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
								IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
								IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
								lcSuma + [ as suma ] + ;
								[FROM ] + lcSelRul + [ a ] + ;
								[INTO CURSOR crsTva ] + ;
								[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12]
						CASE 'pntvavanz'$lcVariabilatemp
							lcSelect = [SELECT b.id_tva as id_jtva_coloana,a.proc_tvav,CAST(] + IIF(Type(lcSelRul+'.taxcode')#'U',[a.taxcode],[NULL]) + [ as I) as taxcode,a.id_sectie,a.id_gestiune,a.sectie,a.id_lucrare,a.nrord,] + ;
								IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
								IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
								IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
								IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
								lcSuma + [ as suma ] + ;
								[FROM ] + lcSelRul + [ a LEFT JOIN jtva_coloane B ON A.ID_JTVA_COLOANA = B.ID_JTVA_COLOANA ] + ;
								[INTO CURSOR crsTva ] + ;
								[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12]
					ENDCASE 
					&lcSelect
		
					Select crsTva
					I  = 0
					Scan For suma*0 = 0  && sa evit cazurile in care suma este ******
						I = I + 1
						If I = 1
							Select ACTACTAN
							Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
							If Found()
								Scatter Name loAct
								Delete
							Else
								Scatter Name loAct Blank
							Endif
						Endif
						Select crsTva
						Scatter Name loTva
						Select ACTACTAN
						Append Blank
						Gather Name loAct
						Gather Name loTva
						Replace proc_tva With loTva.proc_tvav
						If Empty(lcIDJtva)
							Replace id_jtva_coloana With Null
						Endif
					Endscan
					*!*	modificare facturare in valuta 21.09.2007
				Case 'pnbazaval'$lcVariabila Or 'pntvaval'$lcVariabila
					lcVariabilatemp = lcVariabila
					lcVariabila = &lcVariabila
					lcSumaVal = [sum(&lcVariabila)]
					If 'pnbazaval'$lcVariabilatemp
						*!*				lcSuma = [SUM(]+pnBazaValVanz+[)]
						lcSuma = [ROUND(SUM(]+pnBazaVal+[)*a.curs,gnPc)]
						lcSelect = [SELECT a.id_jtva_coloana,a.proc_tvav,a.taxcode,a.id_sectie,a.id_gestiune,a.sectie,a.id_lucrare,a.nrord,] + ;
							IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
							IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
							IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
							IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
							[NVL(a.id_valuta_vanz,0) as id_valuta,] + ;
							IIF(Type(lcSelRul+'.curs') #'U',[a.curs],[0]) + [ as curs,] + ;
							lcSumaVal + [ as suma_val,] + lcSuma + [ as suma ] + ;
							[FROM ] + lcSelRul + [ a ] + ;
							[INTO CURSOR crsTva ] + ;
							[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14]
					Else
						*!*				lcSuma = [SUM(]+pnTvaValVanz+[)]
						lcSuma = [ROUND(SUM(]+pnTvaVal+[)*a.curs,gnPc)]
						lcSelect = [SELECT b.id_tva as id_jtva_coloana,a.proc_tvav,CAST(] + IIF(Type(lcSelRul+'.taxcode')#'U',[a.taxcode],[NULL]) + [ as I) as taxcode,a.id_sectie,a.id_gestiune,a.sectie,a.id_lucrare,a.nrord,] + ;
							IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
							IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
							IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
							IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
							[NVL(a.id_valuta_vanz,0) as id_valuta,] + ;
							IIF(Type(lcSelRul+'.curs') #'U',[a.curs],[0]) + [ as curs,] + ;
							lcSumaVal + [ as suma_val,] + lcSuma + [ as suma ] + ;
							[FROM ] + lcSelRul + [ a LEFT JOIN jtva_coloane B ON A.ID_JTVA_COLOANA = B.ID_JTVA_COLOANA ] + ;
							[INTO CURSOR crsTva ] + ;
							[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14]
					Endif
					&lcSelect
		
					Select crsTva
					I  = 0
					Scan For suma_val*0 = 0  && sa evit cazurile in care suma este ******
						I = I + 1
						If I = 1
							Select ACTACTAN
							Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
							If Found()
								Scatter Name loAct
								Delete
							Else
								Scatter Name loAct Blank
							Endif
						Endif
						Select crsTva
						Scatter Name loTva
						AddProperty(loTva,[nume_val],poAct.nume_val_vanz)
						Select ACTACTAN
						Append Blank
						Gather Name loAct
						Gather Name loTva
						Replace proc_tva With loTva.proc_tvav
						If Empty(lcIDJtva)
							Replace id_jtva_coloana With Null
						Endif
					Endscan
					*!*	modificare facturare in valuta 21.09.2007	^
				Case 'pnbazabon'$lcVariabila
					*!* v 2.0.24
					*!*				lcSuma = [SUM(ROUND(&lcEticheta,gnPc))]
					lcSuma = [Sum(&pcBazaBonFormula)]
					*!* v 2.0.24 ^
					lcSelect = [SELECT a.id_jtva_coloana,a.proc_tvav,CAST(null as I) as taxcode,a.id_sectie,a.id_gestiune,a.sectie,a.id_lucrare,a.nrord,] + ;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ as suma ] + ;
						[FROM ] + lcSelRul + [ a ] + ;
						[INTO CURSOR crsTva ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12]
					&lcSelect
		
					Select crsTva
					I  = 0
					Scan For suma*0 = 0  && sa evit cazurile in care suma este ******
						I = I + 1
						If I = 1
							Select ACTACTAN
							Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
							If Found()
								Scatter Name loAct
								Delete
							Else
								Scatter Name loAct Blank
							Endif
						Endif
						Select crsTva
						Scatter Name loTva
						Select ACTACTAN
						Append Blank
						Gather Name loAct
						Gather Name loTva
						Replace proc_tva With loTva.proc_tvav
						If Empty(lcIDJtva)
							Replace id_jtva_coloana With Null
						Endif
					Endscan
				Otherwise
		
					Select ACTACTAN
					Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
					If Found()
						If !Empty(lcVariabila)
							Replace suma With &lcVariabila
						Endif
					Endif
					If 'discount' $ lcVariabila
						Replace proc_tva With pnProcDiscount,id_jtva_coloana With &lcIDJtva, taxcode WITH GetTaxCode(m.gnAn, m.gnLuna, dataact, &lcIDJtva, (Thisform.nTvaincasare=1))
					Endif
			Endcase
		Endscan
		
		If Used('crsIcsi')
			Use In crsIcsi
		Endif
		If Used('crsConturiX')
			Use In crsConturiX
		Endif
		If Used('crsNota')
			Use In crsNota
		Endif
		
		*!*	IF USED('rul_temp')
		*!*		USE IN rul_temp
		*!*	ENDIF
		
		*!*	&& completez RUL_TEMP
		*!*	lcRul = ALLTRIM(THIS.osel_dr.cfrom)
		*!*	lcSql = [select * from ] + gcS + [.] + lcRul + [ where 1=2]
		*!*	lcCursor = [rul_temp]
		*!*	lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		*!*	IF lnSucces < 0
		*!*		RETURN .F.
		*!*	ENDIF
		
		*!*	lcCant = LOWER(ALLTRIM(this.osel_dr.cantitate))
		*!*	lcCantTransf = [cant] + iif(lcCant = [cante],[],[e])
		
		*!*	IF INLIST(oset.model, 5, 6) && TRANSFER, RETUR TRANSFER
		
		*!*		SELECT * FROM (lcSelRul) INTO CURSOR crsTransf NOFILTER READWRITE
		*!*		REPLACE ALL &lcCantTransf WITH &lcCant FOR !EMPTY(&lcCant)
		*!*		REPLACE ALL &lcCant WITH 0
		*!*		APPEND FROM DBF(lcSelRul)
		*!*		IF oset.id_set <> 89 && TRANSFER INTRE PERSOANE
		*!*			REPLACE ALL cont WITH lcContTr, acont WITH lcAcontTr FOR &lcCantTransf # 0
		*!*		ELSE
		*!*			SELECT (this.ct_grid_search1.cnumecursor)
		*!*			SCATTER NAME loStg
		*!*			SELECT crsTransf
		*!*			REPLACE ALL id_gestin WITH id_gestout
		*!*			REPLACE ALL id_responsabil WITH loStg.id_responsabil, nresp WITH loStg.nresp FOR cante <> 0
		*!*		ENDIF
		*!*		REPLACE ALL id_gestiune WITH id_gestin,nume_gestiune WITH gestin FOR &lcCantTransf <> 0
		*!*		REPLACE ALL id_gestiune WITH id_gestout, nume_gestiune WITH gestout FOR &lcCant <> 0
		*!*
		*!*		SELECT rul_temp
		*!*		APPEND FROM DBF('crsTransf')
		*!*		IF USED('crsTransf')
		*!*			USE IN crsTransf
		*!*		ENDIF
		*!*
		*!*		lcSel = [SELECT id_gestiune from ] + gcs + [.vnom_gestiuni WHERE nr_pag = 6]
		*!*		lcCursor = 'crsIdVanzare'
		*!*		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		*!*		IF lnSucces < 0
		*!*			MESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
		*!*		ENDIF
		*!*
		*!*		IF lnSucces > 0
		*!*			UPDATE rul_temp SET pretv = 0, tvav = 0, proc_tvav = 0 WHERE id_gestiune NOT in (select id_gestiune from crsIdVanzare)
		*!*			USE IN crsIdVanzare
		*!*		ENDIF
		
		*!*	ELSE
		*!*		SELECT rul_temp
		*!*		APPEND FROM DBF(lcSelRul)
		*!*	ENDIF
		
		*!*	IF INLIST(oset.model, 5, 6) AND USED('crsTransfer') && TRANSFER, RETUR TRANSFER
		*!*		SELECT rul_temp
		*!*		APPEND FROM DBF('crsTransfer')
		*!*	ENDIF
		
		*!*	SELECT rul_temp
		*!*	APPEND FROM DBF(lcSelRul)
		
		*!*	modificare	20.04.2007 & 04.05.2007 & 09.05.2007
		Do Case
			Case Inlist(oSet.id_set,61,62,63,226,258,260)		&&	modificare ROAGEST v 2.0.188 : am sters 261
				Select ACTACTAN
				If oSet.cursval
					Calculate Sum(suma) To pnBazaValProd For Alltrim(scc)= '345'
					Calculate Sum(suma) To pnBazaVal341 For Alltrim(scc)= '341'
					Calculate Sum(suma) To pnBazaVal346 For Alltrim(scc)= '346'
					Calculate Sum(suma) To pnBazaValAmb For Alltrim(scc) = '381'
					pnBazaVProd = pnBazaValProd
					pnBazaVAmb = pnBazaValAmb
					pnBazaV341 = pnBazaVal341
					pnBazaV346 = pnBazaVal346
				Else
					Calculate Sum(suma) To pnBazaVProd For Alltrim(scc)= '345'
					Calculate Sum(suma) To pnBazaVAmb For Alltrim(scc) = '381'
					Calculate Sum(suma) To pnBazaV341 For Alltrim(scc)= '341'
					Calculate Sum(suma) To pnBazaV346 For Alltrim(scc)= '346'
				Endif
		
				Replace suma With suma - pnBazaVProd - pnBazaVAmb - pnBazaV341 - pnBazaV346  For Alltrim(SCD) = '4111' And Alltrim(scc) = '707'
		*!*	19.01.2015: 701-> 7015	
		*!*			Replace suma With pnBazaVProd + pnBazaV341 + pnBazaV346  For Alltrim(SCD) = '4111' And Alltrim(scc) = '701'
		
				Replace suma With pnBazaVProd + pnBazaV341 + pnBazaV346  For Alltrim(SCD) = '4111' And Alltrim(scc) = '7015'
		*!*	19.01.2015: 701-> 7015	^
				
				Replace SCD With '711',suma With pnBazaVProd For Alltrim(SCD) = '607' And Alltrim(scc) = '345'
				Replace SCD With '711',suma With pnBazaV341 For Alltrim(SCD) = '607' And Alltrim(scc) = '341'
				Replace SCD With '711',suma With pnBazaV346 For Alltrim(SCD) = '607' And Alltrim(scc) = '346'
				Replace scc With '348' For Inlist(Alltrim(SCD),'341','345','346') And Alltrim(scc) = '378'
				Replace SCD With '348',scc With '711' For Alltrim(SCD) = '378' And Inlist(Alltrim(scc),'341','345','346')
		
				Replace suma With pnBazaVAmb For Alltrim(SCD) = '4111' And Alltrim(scc) = '708'
				Replace SCD With '608' For Alltrim(SCD) = '607' And Alltrim(scc) = '381'
				Replace scc With '388' For Alltrim(SCD) = '381' And Alltrim(scc) = '378'
				Replace SCD With '388' For Alltrim(SCD) = '378' And Alltrim(scc) = '381'
		
				Delete For suma = 0
			Case Inlist(oSet.id_set,79,83,206,225)
				Select ACTACTAN
				Replace scc With '711' For Alltrim(SCD) = '348'
				*!* modificare 22.05.2007
			Case oSet.id_set = 218  &&	diferenta de pret
				Select (lcSelRul)
				Replace All pretv With 0,tvav With 0,proc_tvav With 0,procent With 0
				Select ACTACTAN
				Replace id_gestin With 0,gestin With '' For nr_nota = 2
				*!*		Replace id_gestin With id_gestout, gestin With gestout,id_gestout With 0,gestout With '',scc WITH '711' For nr_nota = 4
				*!*		Replace scc WITH '711' For nr_nota = 4
				Replace SCD With '348' For nr_nota = 2 And SCD <> '381'
				Replace SCD With '388' For nr_nota = 2 And SCD = '381'
				Replace scc With '388' For nr_nota = 1 And SCD = '381'
				*!* modificare 22.05.2007 ^
			Case Inlist(oSet.id_set,53,213,57,58)
				Select ACTACTAN
				Replace SCD With '607' For scc = '371'
				Replace SCD With '711' For scc = '345'		&&	modificare 03.10.2007
			Case Inlist(oSet.id_set, 230, 232, 233, 235,243,244,261,262,270) && protocol, sponsorizare
		
				Select ACTACTAN
				Replace suma With suma * (-1) For nr_nota = 1
				*!*	modificare v 2.2.29
				IF INLIST(oSet.id_set, 232, 235, 244, 262)
					Replace proc_tva WITH 0 FOR nr_nota = 1
				Endif
				*!*	modificare v 2.2.29	^
		Endcase
		*!*	modificare ^
		
		&& ordonez notele contabile in ACTACTANSELECT actactan
		Select ACTACTAN
		
		Sum suma To lnSume
		
		If lnSume <> 0
			lcCondDele = [!(suma = 0 and !(((left(scd,1) = '3' and left(scc,2) = '40') OR (left(scd,2) = '41' and left(scc,1) = '7')) AND proc_tva # 1))]
		Else
			*!*	modificare ROAGEST v 2.0.55
			*!*		lcCondDele = [suma = 0 AND nr_nota = 1 ]
			lcCondDele = [(suma = 0 and nr_nota = 1) or suma <> 0]
			*!*	modificare ROAGEST v 2.0.55	^
		Endif
		*!* 19.02.2010
		*!* 230,232,233,235 = protocol, sponsorizare
		*!* 264,265 = finalizare aprovizionare - are o nota nimic = 401 cu suma 0 care trebuie sa ramana pentru numele furnizorului
		Select * From ACTACTAN Into Cursor crsActActan Where &lcCondDele Or Inlist(id_set, 89, 210, 211, 212, 230, 232, 233, 235,261,264,265) Order By nr_nota NOFILTER Readwrite
		*!* 19.02.2010 ^
		
		Select ACTACTAN
		Delete From ACTACTAN
		Append From Dbf('crsactactan')
		If Used('crsactactan')
			Use In crsActActan
		Endif
		
		*** && completare analitice
		*!* 2.0.85
		*!* sterg analiticele puse datorita lui X = 378 si X = 4428 (X este de la gestiunea destinatie, nu sursa)
		If Inlist(oSet.id_set, 255, 256) && retur de la gestiune valorica - mf pa *
			Replace All ascd With "" For Inlist(Alltrim(scc), '378', '4428')
		Endif
		*!* 2.0.85 ^
		
		Select ACTACTAN
		Scan For Empty(Nvl(ascd,''))
			Scatter Name loActactan
			If Type('loActactan.cont') = 'U'
				x = AddProperty(loActactan,'cont',loActactan.SCD)
			Endif
			If oSet.model = 2 And Type('loActactan.id_gestiune') = 'U' And !Inlist(oSet.id_set,215,216,237,257) && NIR, fara intrare din gestiune valorica
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestin)
			Endif
			If (Inlist(oSet.model, 3, 4) Or Inlist(oSet.id_set,215,216,237,257)) And Type('loActactan.id_gestiune') = 'U'    && BON, RETUR,  intrare din gestiune valorica
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestout)
			Endif
			loActactan.ascd = This.assign_analitic(loActactan.SCD,This.cobj,'loActactan')
			Replace ascd With loActactan.ascd
			Select ACTACTAN
		Endscan
		Select ACTACTAN
		Scan For Empty(Nvl(ascc,''))
			Scatter Name loActactan
			If Type('loActactan.cont') = 'U'
				x = AddProperty(loActactan,'cont',loActactan.scc)
			Endif
			If oSet.model = 2 And Type('loActactan.id_gestiune') = 'U' And !Inlist(oSet.id_set,215,216,237,257) && NIR, fara intrare din gestiune valorica
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestin)
			Endif
			If (Inlist(oSet.model, 3, 4) Or Inlist(oSet.id_set,215,216,237,257)) And Type('loActactan.id_gestiune') = 'U'    && BON, RETUR,  intrare din gestiune valorica
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestout)
			Endif
			loActactan.ascc = This.assign_analitic(loActactan.scc,This.cobj,'loActactan')
			Replace ascc With loActactan.ascc
			Select ACTACTAN
		Endscan
		
		**********************************************
		* OBIECTE DE INVENTAR IN FOLOSINTA
		Use In (SELECT('RUL_TEMP_OBINV'))
		**********************************************
		DO CASE 
			CASE oSet.id_set = 55 
				* DARE IN FOLOSINTA 8039 cu inregistrarea cheltuielii 603 = 303
				* Mut inregistrarea cant<>0 in rul_temp_obinv
				* id_set = 55 dare in folosinta cu schimbarea contului in 8039
				* schimb contul in 8039
				Update rul_temp Set Cont = gcContObinv, acont = '', serie = serie_obinv Where cant <> 0
		
			CASE oSet.id_set = 273
				* DARE IN FOLOSINTA 303 fara inregistrarea cheltuielii 303 = 303
				* Nu schimb contul
				Select * From rul_temp Where cant <> 0 And !Deleted() Into Cursor RUL_TEMP_OBINV NOFILTER Readwrite		
				UPDATE rul_temp_obinv SET serie = serie_obinv
				Delete all FOR cant<>0 IN rul_temp
						
			CASE INLIST(oset.id_set, 70,71,89,104,210,211,212,274)
				* casare 70, retur din folosinta 71, 89 transfer intre persoane, 104 imputare, 210-212 transfer persoane-magazie, 274 = inregistrare cheltuiala ob inv in fol.
				* operatii cu ob. inv. in folosinta nu mai tin seama de contul 8039, intrucat pot fi ob inv in folos si cu contul 303 (id_Set = 274)
				Select * From rul_temp Where !Deleted() Into Cursor RUL_TEMP_OBINV NOFILTER Readwrite
		
				IF oset.id_set = 71
					* 71 retur din folosinta, trebuie sa existe iesirea si in rul_temp, ca sa reintre in stoc
					Delete all FOR Left(Cont,2) = '80' IN rul_temp
					Delete all FOR Left(Cont,2) <> '80' IN rul_temp_obinv
				ELSE 
					Delete all IN rul_temp	
				ENDIF 	
		ENDCASE 		
		IF !USED('RUL_TEMP_OBINV')
			Select * From rul_temp Where Left(Cont,2) = '80'  And !Deleted() Into Cursor RUL_TEMP_OBINV NOFILTER Readwrite
			Delete all FOR Left(Cont,2) = '80' IN rul_temp
		ELSE 
			Select * From rul_temp Where Left(Cont,2) = '80'  And !Deleted() Into Cursor RUL_TEMP_OBINV2 NOFILTER Readwrite
			Delete all FOR Left(Cont,2) = '80' IN rul_temp
			SELECT rul_temp_obinv
			APPEND FROM DBF('rul_temp_obinv2')
			USE IN (SELECT('rul_temp_obinv2'))
		ENDIF 	
		**********************************************
		If gnCMP = 1 And oSet.model = 2 && NIR
			Thisform.analiza_cmp('rul_temp', 'actactan')
			*!*	modificare 24.11.2006
		Else
			If Inlist(oSet.id_set, 215,216,236,237,238,239,240,241,242,255,256,257,259,260) && intrare din gestiune valorica, retur din gestiune valorica
				Replace All id_tip_rulaj With oSet.id_tip_rul
			Else
				Select rul_temp
				Replace id_tip_rulaj With oSet.id_tip_rul For id_tip_rulaj = 0
				*!*	modificare 24.11.2006 ^
			ENDIF
			
			IF INLIST(oSet.id_set, 55,89,210,211,212,273,274) && obiecte inventar in folosinta
				SELECT rul_temp_obinv
				Replace All id_tip_rulaj With oSet.id_tip_rul
			ENDIF 
		Endif
		
		If Type('loActactan') = 'O'
			Release loActactan
		Endif
		
		Do Case
			*!*	modificare ROAFACTURARE	v 2.0.96
			CASE oSet.id_set = 267 && EDITURA EDUARD AVIZ RETUR MARFA DIN CUSTODIE VALORIC
				Select rul_temp
				Replace All id_tip_rulaj With oSet.id_tip_rul
				* Atentie! pot fi mai multe randuri tva vanzare si marfa custodie (357) datorita impartirii pe gestiuni, sectii
				* TVA discount este calculat pe total, nu pe gestiuni, sectii. Trebuie sa il pun doar pe prima linie
				* nr_nota = 1 357 = 371 pot fi de asemenea mai multe randuri datorita impartirii pe gestiuni, sectii
				* nu trebuie sa pun suma totala pe toate randurile nr_nota = 1, ci doar pe o singura nota
				SELECT actactan
		*!*			replace suma WITH suma+pnTvaDiscV FOR INLIST(nr_nota,4,6) && adun tva discount la tva vanzare (-)
				LOCATE FOR nr_nota = 4
				IF FOUND()
					replace suma WITH suma+pnTvaDiscV && adun tva discount la tva vanzare (-) doar pe primul rand 4
				ENDIF 	
				LOCATE FOR nr_nota = 6
				IF FOUND()
					replace suma WITH suma+pnTvaDiscV && adun tva discount la tva vanzare (-) doar pe primul rand 6
				ENDIF 	
				CALCULATE SUM(suma) FOR INLIST(nr_nota,2,3,4) TO lnSumaCont357 && valoarea marfa custodie (357) = marfa la pret de achizitie (2) + adaos (3) + tva (4)
				CALCULATE SUM(suma) FOR nr_nota = 1 TO lnSumaCont357b && valoare bon pret achizitie
				LOCATE FOR nr_nota = 1 && completez pe primul rand nr_nota = 1 cu diferenta dintre valoare 357 si valoarea bon de pe toate randurile nr_nota = 1
				IF FOUND()		
					replace suma WITH suma + (lnSumaCont357 - m.lnSumaCont357b)
				ENDIF 
			*!*	modificare ROAFACTURARE	v 2.0.96	^
			Case oSet.id_set=69
				*!*	modificare 07.03.2006	&&	24.02.2007
				Select ACTACTAN
				Calculate Max(proc_tva) To lnMaxProcTva
				Calculate Min(id_jtva_coloana) For proc_tva = lnMaxProcTva To lnIdJtvaColoana
				Scan For Left(SCD,3)='411' Or Left(scc,3)='411'
					If proc_tva=0
						Replace proc_tva With lnMaxProcTva,id_jtva_coloana With lnIdJtvaColoana
					Endif
				Endscan
				*!*	sfarsit modificare 07.03.2006
			Case  oSet.id_set = 213
				*!*	modificare 12.02.2007	(bon de consum pe lucrari in curs de executie la Materii prime si materiale)
				Select rul_temp
				Replace All pretv With Round(Pret,gnPPretV)		&&	modificare 14.09.2007
				*!*	modificare 12.02.2007 ^
				*!*	modificare	v 2.0.6
			Case Inlist(oSet.id_set,215,216,257)
				Select (lcSelRul)
				Replace All id_gestiunec With poAct.id_gestout,id_gestout With poAct.id_gestout,gestout With poAct.gestout
				Select ACTACTAN
				Replace All id_gestout With poAct.id_gestout,gestout With poAct.gestout
				*!*	modificare	v 2.0.6	^
			Case Inlist(oSet.id_set, 240, 242,256) && Retur din transfer de la gestiune valorica (cantitativ) la pret de vanzare - aviz expeditie
				&& e facut ca un nir cu cante < 0 in depozit, adaug inca o inregistrare cu cant < 0 de la magazin
				Select * From rul_temp Into Cursor cReturTemp Readwrite
				Select cReturTemp
				Scan
					Scatter Name poRec
					Replace cant With poRec.cante, cante With 0, id_gestiune With poRec.id_gestiunec, id_gestiunec With poRec.id_gestiune
					poRec.id_gestiune = cReturTemp.id_gestiune
					poRec.id_gestiunec = cReturTemp.id_gestiunec
					poRec.acont = Thisform.assign_analitic(poRec.Cont,Thisform.cobj,'poRec')
					Replace acont With poRec.acont
				Endscan
				Select rul_temp
				Append From Dbf('cReturTemp')
				Use In (Select('cReturTemp'))
				*!*	modificare ROAGEST v 2.0.56
			Case oSet.id_set = 229
				Select rul_temp
				Replace id_part_rez With poAct.vid_part_rez,id_lucrare_rez With poAct.id_lucrare For cant <> 0
				* Nu mai sterg id_part_rez din iesire, pentru ca daca fac un transfer pe un alt client/inapoi in depozit,
				* de pe un articol deja rezervat, se sterge id_part_rez de pe linia originala si nu se mai imperecheaza in stoc
				* Replace id_part_rez With Null,id_lucrare_rez With Null For cante <> 0
				*!*	modificare ROAGEST v 2.0.56		^
				*!* 19.02.2010
			
				*!* 3xx = 401 => 3xx = 32x
			Case Alltrim(Upper(oSet.explicatia)) = 'FINALIZARE APROVIZIONARE'
				Select ACTACTAN
				Scan For Left(SCD,1) = '3' And Alltrim(scc) = '401'
					lcContD = Alltrim(SCD)
					Select crsconfigcvc
					Locate For Alltrim(Cont) = m.lcContD And !Empty(Nvl(cont_aprovizionare, ''))
					If Found()
						lcContC = Alltrim(cont_aprovizionare)
						Replace scc With m.lcContC In ACTACTAN
					Endif
				Endscan  && actactan
				*!* 19.02.2010 ^
		Endcase
		
		Select rul_temp
		Locate For Empty(id_gestiune)
		If Found()
			amessagebox('Nu ati ales gestiunea!',48,"Atentie")
			Return .F.
		Endif
		
		Select RUL_TEMP_OBINV
		Locate For Empty(id_gestiune)
		If Found()
			amessagebox('Nu ati ales gestiunea!',48,"Atentie")
			Return .F.
		Endif
		
		If oSet.productie
		
			If Alltrim(Upper(oSet.formproduc))='FRM_ALEGE_PROD_CANT'
				Select a.*, Recno() As ninreg ;
					FROM ACTACTAN a ;
					WHERE Substr(scc,1,1)='3' And !INLIST(Alltrim(scc), '301', '341', '345') ;
					INTO Cursor cModificari
		
				Select cModificari
				Scan
					Scatter Name loLinie
					lcSCC = Alltrim(scc)
					lnInreg = ninreg
					Select ACTACTAN
					Replace scc With lcSCC, SCD With '301' For Recno() = lnInreg
					Append Blank
					loLinie.SCD = '601'
					loLinie.scc = '301'
					Gather Name loLinie
					Select cModificari
				Endscan
		
				If Used('cModificari')
					Use In cModificari
				Endif
			Endif
		Endif
		
		*!* v 2.0.23 diferente baza, tva la NIR
		*!* daca sunt diferente intre valoarea calculata si valoarea de pe factura inregistrez diferentele
		If oSet.model = 2 && NIR
			loRec = Null
			lnDiferentaValftva = Thisform.nfTotftva - This.ct_factura1.totftva
			lnDiferentaValTva = Thisform.nfTottva - This.ct_factura1.tva
			If lnDiferentaValftva <> 0 And Thisform.nfTotftva <> 0
				Select ACTACTAN
				Locate For Left(scc,2) = '40'
				If Found()
					Scatter Name loRec
					loRec.suma = lnDiferentaValftva
					loRec.explicatia5 = 'Diferente calcul Valoare fara TVA'
					*!*				modificare ROAGEST v 2.0.101 : "ALTE CHELTUIELI DE EXPLOATARE"	
					* Las cont debit = contul original, nu cu 6588 daca nu eset configurare
					IF .F.
						Select crsconfigcvc
						Locate For Cont = Upper(Alltrim(loRec.scd)) && 301, 302...
						If Found() AND !Empty(NVL(cont_diferente, ''))
							loRec.scd = Alltrim(cont_diferente)
						ELSE 
							loRec.SCD='6588'	
						ENDIF			
						loRec.ascd=''
					ENDIF 	
					*!*				modificare ROAGEST v 2.0.101 ^
					Insert Into ACTACTAN From Name loRec
					Release loRec
				Else
					amessagebox('Nu s-a gasit nici o inregistrare x = 40x pentru distribuirea diferentei la valoarea fara tva',0+48,'Diferente')
				Endif
			Endif
			If lnDiferentaValTva <> 0 And Thisform.nfTottva <> 0
				Select ACTACTAN
				Locate For Inlist(SCD, '4426', '4428')
				If Found()
					Scatter Name loRec
					loRec.suma = lnDiferentaValTva
					loRec.explicatia5 = 'Diferente calcul TVA'
					Insert Into ACTACTAN From Name loRec
					Release loRec
				Else
					amessagebox('Nu s-a gasit nici o inregistrare x = 4426/4428 pentru distribuirea diferentei la valoarea tva',0+48,'Diferente')
				Endif
			Endif
		Endif
		*!* v 2.0.23 ^
		
		Do completare_parteneri_gestiune In ointroduceri.prg
		Do completare_gruputil_analitice In oproceduri_comune.prg
		Do completare_tva_analitice In oproceduri_comune.prg
		
		* Achizitii din CE, modific 4426 = 401 in 4426 = 4427
		Select ACTACTAN
		Replace All scc With '4427', ascc WITH '', id_partc WITH 0, partc WITH '' For scd = '4426' AND LEFT(scc,1) = '4' AND IsJCJtvaCE(id_jtva_coloana) IN ACTACTAN
			
		Select ACTACTAN
		*!*	modificare	ROAGEST v 2.2.0
		If Thisform.ntvaincasare = 1
			Replace All scc With '4428',ascc WITH '' For Inlist(id_jtva_coloana,22,24,26,30,32,38,42) And scc = '4427'
			Replace All scd With '4428',ascd WITH '' For Inlist(id_jtva_coloana,171,173,175,179,189,211,215) And scd = '4426'
			If Upper(Alltrim(Nvl(oSet.tipJurnal, ''))) = 'JC' && FURNIZORI / PASIV
				lcSCTrez = 'scc'
				lcSCTVA = 'scd'
			Else
				lcSCTrez = 'scd'
				lcSCTVA = 'scc'
			ENDIF
			
		*!*		15.04.2013 - dupa ce puneam la loc 4428, ramanea cu analiticele de pe 4426 sau 4427
			Do completare_gruputil_analitice In oproceduri_comune.prg
			Do completare_tva_analitice In oproceduri_comune.prg
		*!*		 ^15.04.2013
		
		*** caut linia cu PLATA 401 = 5XX / INCASAREA 5XX = 411
			Select actactan
			Locate For Inlist(Alltrim(&lcSCTrez),'5121','5124','5311','5314', '542') && scc = '5xx' / scd = '5xx'
			If Found()
				*lnNrChitanta = evaluate(Thisform.cobj + [.nrchitanta])
				lnNrChitanta = IIF(Type(Thisform.cobj +[.nrchitanta])<>'U',Evaluate(Thisform.cobj +[.nrchitanta]),Evaluate(Thisform.cobj +[.nract]))
		
				lnIdFdoc = IIF(Type(Thisform.cobj+[.id_fdoc2])<>'U',Evaluate(Thisform.cobj+[.id_fdoc2]),Evaluate(Thisform.cobj+[.id_fdoc]))
				lcFdoc = IIF(Type(Thisform.cobj+[.fdocpl])<>'U',Evaluate(Thisform.cobj+[.fdocpl]),Evaluate(Thisform.cobj+[.fdoc]))
						
				Insert Into actactan(nr_nota,luna,an,nract,scd,ascc,scc,;
					suma,suma_val,pereched,perechec,explicatia4,explicatia5,Curs,id_util,;
					id_responsabil,nresp,id_venchelt,dst_chlt,id_lucrare,nrord,;
					id_ctr,contract,id_sectie,sectie,proc_tva,id_set,id_fact,;
					id_factd,id_factc,id_partd,partd,id_partc,partc,;
					id_sucursala,sucursala,id_fdoc,fdoc,id_gestin,id_jtva_coloana,taxcode,;
					gestin,id_gestout,gestout,id_valuta,nume_val,dataact,dataireg);
					Select a.nr_nota, a.luna, a.an, lnNrChitanta As nract,'4426' As  scd,a.ascd As ascc,'4428' As scc,;
					a.suma, a.suma_val,a.nract As pereched,a.perechec,a.explicatia4,a.explicatia5,a.Curs,a.id_util,;
					a.id_responsabil,a.nresp,a.id_venchelt,a.dst_chlt,a.id_lucrare,a.nrord,;
					a.id_ctr,a.contract,a.id_sectie,a.sectie,a.proc_tva,a.id_set,-5 As id_fact,;
					0 As id_factd,0 As id_factc,0 As id_partd,'' As partd, 0 As id_partc, '' As partc,;
					a.id_sucursala,a.sucursala,;
					lnIdFdoc as id_fdoc, lcFdoc as fdoc,;
					0 As id_gestin,;
					c.id_tva As id_jtva_coloana,;
					CAST(GetTaxCode(m.gnAn, m.gnLuna, a.dataact, c.id_tva) as N(6) NULL) as taxcode,;			
					'' As gestin,0 As id_gestout,'' As gestout,a.id_valuta,a.nume_val,a.dataact,a.dataireg ;
					FROM actactan a ;
					Left Join jtva_coloane b On a.id_jtva_coloana = b.id_tva ;
					left Join jtva_coloane c On b.id_jtva_ex = c.id_jtva_coloana ;
					Where a.scd = '4428' And Like('4*',a.scc) And !Isnull(b.id_jtva_ex)
		
				Insert Into actactan(nr_nota,luna,an,nract,scc,ascd,scd,;
					suma,suma_val,pereched,perechec,explicatia4,explicatia5,Curs,id_util,;
					id_responsabil,nresp,id_venchelt,dst_chlt,id_lucrare,nrord,;
					id_ctr,contract,id_sectie,sectie,proc_tva,id_set,id_fact,;
					id_factd,id_factc,id_partd,partd,id_partc,partc,;
					id_sucursala,sucursala,id_fdoc,fdoc,id_gestin,id_jtva_coloana,taxcode,;
					gestin,id_gestout,gestout,id_valuta,nume_val,dataact,dataireg);
					Select a.nr_nota, a.luna, a.an, lnNrChitanta As nract,'4427' As  scc,a.ascc As ascd,'4428' As scd,;
					a.suma, a.suma_val, a.pereched,a.nract As perechec,a.explicatia4,a.explicatia5,a.Curs,a.id_util,;
					a.id_responsabil,a.nresp,a.id_venchelt,a.dst_chlt,a.id_lucrare,a.nrord,;
					a.id_ctr,a.contract,a.id_sectie,a.sectie,a.proc_tva,a.id_set,-5 As id_fact,;
					0 As id_factd,0 As id_factc,0 As id_partd,'' As partd, 0 As id_partc, '' As partc,;
					a.id_sucursala,a.sucursala,;
					lnIdFdoc as id_fdoc, lcFdoc as fdoc,;
					0 As id_gestin,;
					c.id_tva As id_jtva_coloana,;
					CAST(GetTaxCode(m.gnAn, m.gnLuna, a.dataact, c.id_tva) as N(6) NULL) as taxcode,;			
					'' As gestin,0 As id_gestout,'' As gestout,a.id_valuta,a.nume_val,a.dataact,a.dataireg ;
					FROM actactan a ;
					Left Join jtva_coloane b On a.id_jtva_coloana = b.id_tva ;
					left Join jtva_coloane c On b.id_jtva_ex = c.id_jtva_coloana ;
					Where a.scc = '4428' And Like('4*',a.scd) And !Isnull(b.id_jtva_ex)
			Endif
		Endif
		*!*	modificare	ROAGEST v 2.2.0	^
		DO completare_taxname IN oproceduri_comune.prg
		DO completare_paymentname IN oproceduri_comune.prg
		DO completare_explicatie_tva IN oproceduri_comune.prg
		
		Go TOP IN actactan
		
		***** articolele negestionabile nu intra in stoc 2009.02.17
		Delete From (lcSelRul) Where in_stoc = 0
		***** 2009.02.17  ^
		
		Return .T.
		
	ENDPROC

	PROCEDURE intrare_produs
		Select rul_temp
		Append Blank
		Replace id_articol With m.pnId_articol, ;
			denumire With m.pcDenumire, ;
			cant With m.pnCant, ;
			lot WITH m.pcLot, ;
			serie WITH m.pcSerie, ;
			pret With ROUND(Thisform.ntotal/pnCant,gnPPret), ;
			id_gestiune With pnId_gestiune, nume_gestiune With pcGestiune, ;
			id_gestin With pnId_gestiune, gestout With pcGestiune, ;
			cont With pcCont_articol, ;
			nnir With poact.nnir, ;
			dataact With poact.dataact, ;
			datain With poact.dataact, ;
			id_set With poact.id_set, ;
			in_stoc WITH pnInStoc,;
			in_crm WITH pnInCrm ;
			um WITH pcUm ;
			nract WITH poAct.nract
		*!*	modificare ROAPRODUCTIE v 2.0.2 : am adaugat ce este sub id_set
		*!*	proc_tva	?
		
		
	ENDPROC

	PROCEDURE KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl
		
		LOCAL lcCtrGrid, lcCtrCriteriu, lcControl
		lcCtrGrid = []
		lcCtrCriteriu = []
		
		lcControl = UPPER(THIS.ACTIVECONTROL.NAME)
		IF lcControl = '_GRID1'
			lcCtrGrid = UPPER(THIS.ACTIVECONTROL.COMMENT)
		ENDIF
		
		IF lcControl = 'CRITERIU'
			lcCtrCriteriu = UPPER(THIS.ACTIVECONTROL.COMMENT)
		ENDIF
		
		DO CASE
			CASE nKeyCode = 13 AND 'GRD_ST' $ lcCtrGrid
				NODEFAULT
				THISFORM.urmator1.comMAND1.SETFOCUS
		
			CASE nKeyCode = 13 AND 'GRD_DR' $ lcCtrGrid
				NODEFAULT
				THISFORM.ct_grid_search1.Cb_tx_cautare1.TEXT.SETFOCUS
		
			CASE (nKeyCode >=33 AND nKeyCode <=122) AND ('CRITERIU_ST' $ lcCtrCriteriu OR 'GRD_ST' $ lcCtrGrid)
				NODEFAULT
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE = ALLTRIM(THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE) + CHR(nKeyCode)
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
		
			CASE (nKeyCode = 127) AND ('CRITERIU_ST' $ lcCtrCriteriu OR 'GRD_ST' $ lcCtrGrid) && backspace
				NODEFAULT
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE = LEFT(ALLTRIM(THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE),LEN(ALLTRIM(THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE))-1)
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
		
			CASE (nKeyCode >=33 AND nKeyCode <=122) AND ('CRITERIU_DR' $ lcCtrCriteriu OR 'GRD_DR' $ lcCtrGrid)
				NODEFAULT
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE = ALLTRIM(THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE) + CHR(nKeyCode)
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
		
			CASE (nKeyCode = 127) AND ('CRITERIU_DR' $ lcCtrCriteriu OR 'GRD_DR' $ lcCtrGrid) && backspace
				NODEFAULT
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE = LEFT(ALLTRIM(THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE),LEN(ALLTRIM(THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE))-1)
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
			CASE INLIST(nKeyCode, 13, 9, 4, 24) AND '_CBBASE1'$lcControl
				NODEFAULT 
				thisform.ct_grid_search1.cb_tx_cautare1.text.SetFocus
		 
			OTHERWISE
				DODEFAULT(nKeyCode, nShiftAltCtrl)
		ENDCASE
		
	ENDPROC

	PROCEDURE modificare_lista_preturi
		Lparameters tnIdPol, tnIdArticol, tnPretftvaLista, tnPretvtvaLista, tnPretLista, tnProcTvav, tnPretListaVechi
		
		&& tnPretListaVechi - apare doar la operatiile de retur
		&& la NIR se modifica automat pretul de lista
		If Type('tnPretListaVechi') = 'N' and Nvl(tnIdPol,0) <> 0 
			If aMessagebox(Alltrim(OSTG.denumire)+" are pretul " + ;
				Alltrim(Str(tnPretListaVechi,16, gnPPretV)) + [ in politicile de preturi.] + Alltrim(Str(tnIdPol)) + Chr(13) + Chr(10) + ;
				[Doriti sa il schimbati cu ]+Alltrim(Str(tnPretLista,16, gnPPretV))+[?],4+32) <> 6
				Return
			Endif
		Endif
		
		
		*!* MODIFICARE PRETURI IN LISTA DE PRETURI PENTRU NIR-UL CU MODIFICAREA LISTEI DE PRETURI (ID_SET = 231 NIR MF PV LISTA DE PRETURI)
		
		Local lcSql, lcSelect
		lcSelect = Select()
		
		*!* verific daca exista articolul in politica de preturi
		lcSql = [Select id_pol_art, id_venchelt, proc_tvav from crm_politici_pret_art where id_pol = ] + Alltrim(Str(tnIdPol)) + [ and id_articol = ] + Alltrim(Str(tnIdArticol))
		lnSucces = goExecutor.oExecute(m.lcSql, "cPoliticiPretArt")
		If lnSucces < 0
			aMessageBox(goExecutor.cEroare,0+16, 'Eroare')
		
			Select (lcSelect)
			Return
		Endif
		Select cPoliticiPretArt
		Scatter Name loPoliticaPretArt
		Use In (Select('cPoliticiPretArt'))
		
		
		&& TRANZACTIE MANUALA (MODIFICARE CRM_POLITICI_PRET_ART, CRM_POLITICI_PRETURI)
		lnSucces = SQLSetprop(gnHandle,"Transactions",2)
		If lnSucces < 0
			aMessageBox("Programul nu a trecut pe tranzactie manuala",4+48,'Lista preturi')
		
			Select (lcSelect)
			Return
		Endif
		
		*!* ADAUGARE ARTICOL NOU IN LISTA DE PRETURI SAU MODIFICARE ARTICOL EXISTENT
		If Nvl(loPoliticaPretArt.id_pol_art,0) = 0
			lcSql = [begin pack_preturi.adauga_politica_pret_art(] + ;
				ALLTRIM(Str(tnIdPol)) + [,] + ; && id_pol
			Alltrim(Str(tnIdArticol)) + [,] + ; && id_articol
			Alltrim(Str(tnPretLista,20,4)) + [,] + ; && pret
			Alltrim(Str(tnPretftvaLista,20,4)) + [,] + ;  && pretftva
			Alltrim(Str(tnPretvtvaLista ,20,4)) + [,] + ; && pretctva
			[NULL, ] + ; && id_valuta
			Alltrim(Str(tnProcTvav,20,4)) + [,] + ; && proc_tvav
			[NULL, ] + ; && procent
			[NULL, ] + ; && id_venchelt
			Alltrim(Str(gnIdUtil)) + ; && id_util
			[); end;]
		Else
			lcSql = [begin pack_preturi.modifica_pret_pol_pret_art(] + ;
				ALLTRIM(Str(loPoliticaPretArt.id_pol_art)) + [,] + ; && id_pol_art
			Alltrim(Str(tnPretLista,20,4)) + [,] + ; && pret
			Alltrim(Str(tnPretftvaLista,20,4)) + [,] + ;  && pretftva
			Alltrim(Str(tnPretvtvaLista ,20,4)) + [,] + ; && pretctva
			Iif(Isnull(loPoliticaPretArt.id_venchelt), 'NULL',Alltrim(Str(loPoliticaPretArt.id_venchelt))) + [,] + ; && id_venchelt
			Iif(Isnull(loPoliticaPretArt.proc_tvav), 'NULL', Alltrim(Str(loPoliticaPretArt.proc_tvav,20,4))) + ; && proc_tvav
			[); end;]
		Endif && Nvl(lnIdPolArt,0) = 0
		
		
		lnSucces = goExecutor.oExecute(lcSql)
		If lnSucces < 0
			aMessageBox(goExecutor.cEroare,0+16, 'Eroare')
		Else
			*!* MODIFICARE DATAORA, UTIL in CRM_POLITICI_PRETURI
			lcSql = [begin pack_preturi.modifica_politica_dataora(] + ;
				ALLTRIM(Str(tnIdPol)) + [,] + ; && id_pol
			Alltrim(Str(gnIdUtil)) + ; && id_util
			[); end;]
			lnSucces = goExecutor.oExecute(lcSql)
			If lnSucces < 0
				aMessageBox(goExecutor.cEroare,0+16, 'Eroare')
			Endif
		Endif
		
		*!* COMMIT / ROLLBACK
		If lnSucces > 0
			lnSucces = goExecutor.oExecute("COMMIT")
			If lnSucces < 0
				aMessageBox(goExecutor.cEroare,0+16, 'Eroare')
			Endif
		Else
			lnSucces = goExecutor.oExecute("ROLLBACK")
			If lnSucces < 0
				aMessageBox(goExecutor.cEroare,0+16, 'Eroare')
			Endif
		Endif
		
		SQLSetprop(gnHandle,"Transactions",1)
		
		Select (lcSelect)
		
		
	ENDPROC

	PROCEDURE Release
		lcSelRul = this.ct_grid_order1.cnumecursor 
		lcSelSt = this.ct_grid_search1.cnumecursor 
		IF USED(lcSelRul)
			USE IN (lcSelRul)
		ENDIF 
		IF USED(lcSelSt)
			USE IN (lcSelSt)
		ENDIF 
		IF USED('crsTransfer')
			USE IN crsTransfer
		ENDIF 
	ENDPROC

	PROCEDURE Show
		*!* 18.08.2017
		*!* marius.mutu
		*!* Completare tabel dreapta pentru MODIFICARE NIR/BON
		
		Lparameters nStyle
		
		Local lcObj, lcSelRul, lcSql
		private pnCod
		lcObj = Thisform.cobj
		lcSelRul = This.ct_grid_order1.cnumecursor
		This.lbTotal.Caption = 'TOTAL ' + This.CTip_frm
		This.ct_grid_order1.initializare(.T.)
		*!*	modificare	v 2.1.19 : la bon/factura nu-l las sa ordoneze dupa alte coloane 
		If oset.model = 3
			This.ct_grid_search1.ccoloanepermise = [codmat,denumire,serie,pret]
		Endif
		*!*	modificare	v 2.1.19	^
		This.ct_grid_search1.initializare(.T.)
		
		* MODIFICARE NIR/BON
		If Pemstatus(This, 'lCorectie', 5) And Pemstatus(This, 'nCod', 5) And Type('this.nCod') = 'N' And This.lCorectie And This.nCod > 0
			pnCod = This.nCod
			lcSql = [select * from vrul where cod = ?pnCod]
			lnSucces = goExecutor.oExecute(m.lcSql, 'cRulTemp')
			IF lnSucces > 0
				Select (m.lcSelRul)
				Append From Dbf('cRulTemp')
			ELSE
				AMESSAGEBOX(goExecutor.cEroare,0+48,_screen.Caption)	
			ENDIF 
			USE IN (SELECT('cRulTemp'))	
		ENDIF
		
		This.calcul_sume(lcSelRul)
		This.ct_grid_search1.cb_tx_cautare1.SetFocus
		*!*	modificare	v 2.1.34
		If Type(Thisform.ct_grid_search1.cnumecursor + ".in_stoc") <> "U"
			If oset.model >= 3
				Thisform.ct_grid_search1._GRID1.SetAll("DynamicForeColor", "IIF(in_stoc=0,RGB(255,0,0),RGB(0,0,0))", "Column")
			Else
				Thisform.ct_grid_search1._GRID1.SetAll("DynamicForeColor", "IIF(in_stoc=0,RGB(0,128,128),RGB(0,0,0))", "Column")
			Endif
		Endif
		*!*	modificare	v 2.1.34	^
		*!* v 2.0.22 diferente de calcul NIR
		*!* doar pe nir afisez texboxurile pentru diferente
		If oset.model = 2 && NIR
			This.ct_factura1.txfTotal.Visible = .T.
			This.ct_factura1.txfBaza.Visible = .T.
			This.ct_factura1.txfTva.Visible = .T.
		Endif
		*!* v 2.0.22 ^
		If Inlist(poact.id_set, 105, 106)
			Thisform.ct_grid_search1.cboListe.Visible = .T.
			Thisform.ct_grid_search1.lb_listePreturi.Visible = .T.
		Endif
		
		If oxset.cursval
			With Thisform.ct_factura2
				.lb_valuta.Caption = [(] + &lcObj..nume_val_vanz + [)]
				With .lb_curs
					.Caption = [Curs ] + Dtoc(&lcObj..v8) + [ : ] + Alltrim(Str(&lcObj..Curs, 14, 4))
					.AutoSize = .T.
				Endwith
			Endwith
		Endif
		
		If oset.productie And Inlist(oset.id_set, 26003, 26004)	&&	modificare 17.10.2007
			Thisform.container_valoare_decontata1.Visible = .T.
		Endif
		
		&& transfer catre gest la pret vz, Intrare din transfer de la gest. valorica la pret de vanz.,
		&& protocol, sponsorizare
		If Inlist(oset.id_set, 75, 216, 230, 232, 233, 235, 257, 261, 267)
			Thisform.lb_totalctva.Visible = .T.
			Thisform.tx_totalctva.Visible = .T.
		Endif
		
		*!*	modificare v 2.2.0
		Thisform.nTvaincasare = &lcObj..tva_incasare
		*!*	modificare v 2.2.0	^
		*!*	modificare v 2.2.29
		Thisform.omemopref = Createobject("Custom")
		AddProperty(Thisform.omemopref, "id_jtva_ach", 0)
		AddProperty(Thisform.omemopref, "proc_tva", 0.01)
		AddProperty(Thisform.omemopref, "id_jtva_vanz", 0)
		AddProperty(Thisform.omemopref, "proc_tvav", 0.01)
		*!*	modificare v 2.2.29	^
		DoDefault(nStyle)
		
	ENDPROC

	PROCEDURE Ct_discount1.Init
		*!* 19.10.2017
		*!* marius.mutu
		*!* s-a tratat cazul in care firma este cu TVA Incasare si trebuie id_jtax neexigibil in loc de exigibil
		*!*	modificare	2.2.4	:	am inlocuit jtva_coloane cu crsjtax
		Local lnIdJtva, lnProc_tva, lnproc, loTVA
		
		lnIdJtva = oSet.id_jtax && achizitii int. 19%
		loTVA = GeJtvaColoana(m.lnIdJtva, poAct.tva_incasare, NVL(oSet.tipjurnal, 'JC'))
		lnIdJtva = loTVA.id_jtva_coloana
		
		Select crsjtax
		Locate For id_jtva_coloana = m.lnIdJtva
		If !Found()
			Go Top
		Endif
		This.lb_explicatie_tva.Caption = Alltrim(Upper(denumire))
		lnProc_tva = (cota_tva + 100) / 100
		lnproc = cota_tva
		This.pntva = lnProc_tva
		This.nid_jtva_coloana = id_jtva_coloana
		This.nid_tva = id_tva
		This.cotaTva.ListIndex = Recno()
		
		
		
		
	ENDPROC

	PROCEDURE Ct_discount1.Refresh
		DODEFAULT()
		lcSelRul = thisform.ct_grid_order1.cnumecursor 
		this.Parent.calcul_sume(lcSelRul)
	ENDPROC

	PROCEDURE Ct_factura1.txfBaza.Valid
		thisform.nftotctva = thisform.nftotftva + thisform.nftottva 
		thisform.ct_factura1.txftotal.Refresh 
	ENDPROC

	PROCEDURE Ct_factura1.txfTva.Valid
		thisform.nftotctva = thisform.nftotftva + thisform.nftottva
		thisform.ct_factura1.txftotal.Refresh 
	ENDPROC

	PROCEDURE Ct_grid_order1.Cb_tx_gestin._CBBASE1.LostFocus
		SELECT nom_gestiuni
		pcobj.id_gestin = id_GESTiune
		pcobj.gestin = nume_gestiune
		pcObj.cgest = cgest
		pcobj.id_GESTiune = id_GESTiune
		pcobj.nume_gestiune = nume_gestiune
	ENDPROC

	PROCEDURE Ct_grid_search1.actualizeaza_grid
		*!* 12.06.2017
		*!* marius.mutu
		*!* am pus conditii suplimentare la dynamicbackcolor sa nu mai dea invalid expression, sper
		
		*!*	modificare	ROAGEST	v 2.1.19
		Lparameters pcFiltru
		DoDefault(pcFiltru)
		If oSet.model = 3
			poLog.Log('recordsource/tooltiptext inainte de This._GRID1.salveaza_grid() ' + ALLTRIM(TRANSFORM(this._griD1.RecordSource)) + '/' + ALLTRIM(TRANSFORM(This._grid1.ToolTipText)), PROGRAM())
			This._GRID1.salveaza_grid()
			poLog.Log('recordsource/tooltiptext dupa This._GRID1.salveaza_grid() ' + ALLTRIM(TRANSFORM(this._griD1.RecordSource)) + '/' + ALLTRIM(TRANSFORM(This._grid1.ToolTipText)), PROGRAM())
			lcCursor1 = Thisform.ct_grid_search1.cnumecursor
			lcCursor2 = Thisform.ct_grid_order1.cnumecursor
			lcCursor3 = [crsTempCurent]
			copiaza_structura_cursor(lcCursor1,lcCursor3)
			Insert Into (lcCursor3) Select * From (lcCursor1)
			If Used(lcCursor1)
				Use In (lcCursor1)
			Endif
			If !Inlist(gnTipGest , 6,7)
				Select a.*,a.cantitate-Nvl(b.cantitate,0) As stoc_actual From (lcCursor3) a ;
					Left Join (Select Sum(cante) As cantitate, id_articol, Nvl(serie,'') As serie,Pret,id_gestout ;
					From (lcCursor2) ;
					WITH (Buffering = .T.) Group By id_gestout,id_articol,serie,Pret) b On a.id_articol = b.id_articol ;
					And a.Pret = b.Pret ;
					AND a.id_gestiune = b.id_gestout ;
					And Nvl(a.serie,'') = Nvl(b.serie,'') ;
					Into Cursor (lcCursor1) Readwrite
			Else
				Select a.*,a.cantitate-Nvl(b.cantitate,0) As stoc_actual From (lcCursor3) a ;
					Left Join (Select Sum(cante) As cantitate, id_articol, Nvl(serie,'') As serie,Pret,pretv,id_gestout ;
					From (lcCursor2) ;
					WITH (Buffering = .T.) Group By id_gestout,id_articol,serie,Pret,pretv) b On a.id_articol = b.id_articol ;
					And a.Pret = b.Pret ;
					AND a.id_gestiune = b.id_gestout ;
					And Nvl(a.serie,'') = Nvl(b.serie,'') ;
					and a.pretv = b.pretv ;
					Into Cursor (lcCursor1) Readwrite
			Endif
			If Used(lcCursor3)
				Use In (lcCursor3)
			ENDIF
			poLog.Log('recordsource/tooltiptext inainte de This._GRID1.incarca_grid() ' + ALLTRIM(TRANSFORM(this._griD1.RecordSource)) + '/' + ALLTRIM(TRANSFORM(This._grid1.ToolTipText)), PROGRAM())	
			This._GRID1.incarca_grid()
			poLog.Log('recordsource/tooltiptext dupa This._GRID1.incarca_grid() ' + ALLTRIM(TRANSFORM(this._griD1.RecordSource)) + '/' + ALLTRIM(TRANSFORM(This._grid1.ToolTipText)), PROGRAM())		
		*!*	modificare	ROAGEST	v 2.1.19
		*!*	If oSet.model = 3
			This._GRID1.SetAll("DynamicBackColor","IIF(USED('" + m.lcCursor1 + "') and TYPE('" + + m.lcCursor1 + ".stoc_actual') = 'N' and " + m.lcCursor1 + ".stoc_actual=0,RGB(128,128,128),RGB(255,255,255))","Column")
		 
		*!*	Endif
		*!*	modificare	ROAGEST	v 2.1.19	^
		Endif
		*!*	modificare	ROAGEST	v 2.1.19	^
	ENDPROC

	PROCEDURE Ct_grid_search1.cboListe.Init
		IF INLIST(poact.id_set,105,106)
			SELECT cListePret
			LOCATE FOR id_pol = poact.id_pol
			this.Value = cListePret.nume_lista_preturi
			this.Refresh 
		ENDIF 
		
	ENDPROC

	PROCEDURE Ct_grid_search1.cboListe.Valid
		pnId_lista = cListePret.id_pol
		
		SELECT cListePret
		pcobj.id_pol = cListePret.id_pol
		thisform.ct_GRID_SEARCH1.initializare(.T.)
		thisform.ct_grid_search1.cb_tx_cautare1.text.SetFocus
		
	ENDPROC

	PROCEDURE Ct_grid_search1.Cb_tx_gestout._CBBASE1.Valid
		Select nom_gestiuni
		pcobj.id_gestout = id_GESTiune
		pcobj.gestout = nume_gestiune
		pcobj.cgest = cgest
		pcobj.id_GESTiune = id_GESTiune
		pcobj.nume_gestiune = nume_gestiune
		Thisform.ct_GRID_SEARCH1.initializare(.T.,.T.)
		*!*	modificare	ROAGEST v 2.1.33
		*!*	This.Parent.Parent.cb_tx_cautare1.Text.SetFocus()
		Return This.Parent.Parent.cb_tx_cautare1.Text
		*!*	modificare	ROAGEST v 2.1.33	^
	ENDPROC

	PROCEDURE Lb_titlu_alb_b121.Init
		If Type('oxset.nume_set') # 'U'
			This.Caption = Proper(Alltrim(oxset.nume_set))
		Endif
		This.Caption = This.Caption + [ ( Nr. document : ] + Alltrim(Nvl(poAct.serie_act,[])) + [ ] + ;
			TRANSFORM(poAct.nract,get_mask(14,0)) + [ ) ]
	ENDPROC

	PROCEDURE Urmator1.Command1.Click
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		*!*		Model =-1 : Nota fara contabilizare
		*!*		Model = 1 : Nota simpla cu contabilizare
		*!*		Model = 2 : NIR
		*!*		Model = 3 : BON/FACTURA VANZARE
		*!*		Model = 4 : Retur BON/FACTURA VANZARE
		*!*		Model = 5 : Transfer
		*!*		Model = 6 : Retur Transfer
		*!*		Model = 7 : Diferenta de pret
		
		*!*		Param1 = 1 : En-detail
		*!*		Param1 = 2 : En-gros
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		*!* 11.05.2009 -ultimul pret de achizitie,vanzare este din ultimii 2 ani
		*!* marius.felecanu
		*!* 26.05.2009 - pentru transfer - sectia si lucrarea se inregistreaza in contabilitate
		*!* marius.felecanu
		*!* 27.05.2009 - se poate adauga acelasi articol de mai multe ori
		*!* marius.felecanu
		
		*!* 30.03.2010
		*!* marius.mutu
		*!* se citeste si rul.proc_tva de la ultima achizitie pentru NIR-urile din lista de preturi - completare automata preturi
		
		*!* 13.09.2010
		*!* marius.mutu
		*!* ultimele preturi de achizitie, vanzare se citesc din RUL_ULTIMA_INTRARE daca este configurata optiunea RG_PRET_ULTIMA_INTRARE
		
		*!* 20.01.2015
		*!* marius.mutu
		*!* se citesc ultimele preturi de achizitie pentru ID_SET = NIR + optiunea gnRG_NIR_ULTIMUL_PRET = 1
		
		*!* 21.12.2015 
		*!* marius.mutu
		*!*	nu mai suprascriu pretul de vanzare din lista de preturi. de ce ar trebui sa il suprascriu?
		
		*!* 22.09.2023
		*!* marius.mutu
		*!* transfer ob inv in folosinta + alte transferuri (oSet.model = 5) corectare gestiune intrare daca se schimba gestiunea sursa
		
		Private poPreturi
		poPreturi = Createobject("empty")
		AddProperty(poPreturi,"pretv", 0)
		AddProperty(poPreturi,"tvav", 0)
		AddProperty(poPreturi,"pretvtva", 0)
		
		Local lnNIRPRETLISTAMOD
		If Type('gnNIRPRETLISTAMOD') <> 'U'
			lnNIRPRETLISTAMOD = gnNIRPRETLISTAMOD
		Else
			lnNIRPRETLISTAMOD = 0
		Endif
		Local lnPretfTva, lnPretvTva, lnListaPreturiCuTva, lcAcont
		Local loPoliticaPretArt
		lnPretfTva = 0
		lnPretvTva = 0
		lnListaPreturiCuTva = 1 && daca lista de preturi are preturile cu tva id_set = 231 nir mf la pv cu modificarea listei de preturi
		loPoliticaPretArt = Null
		
		lcSelRul = Thisform.ct_grid_order1.cnumecursor
		
		*!*	modificare 22.08.2007
		*!*	 La toate conditiile unde era id_articol, am adaugat si NVL(serie,'') , in afara de politicile de preturi si reteta.
		lcIde = [T]
		lcIde = lcIde + ',' + Iif(oset.factura And oset.model = 2, 'F', '') && 2/F = FACTURA DE ACHIZITIE SI NIR
		lcIde = lcIde + ',' + Iif(oset.adaos And (oset.param1 = 1 Or oset.model = 2), 'A,X','')
		lcIde = lcIde + ',' + Iif(oset.discount, 'D','')
		lcIde = lcIde + ',' + Iif(Inlist(oset.model,2), 'N', Iif(Inlist(oset.model, 3, 4, 5, 6, 7), 'B', '')) && 2/N = NIR, B = BON/TRANSFER
		lcIde = Iif(oset.model = 7, lcIde + ',X' , lcIde) && 7 = DIFERENTA DE PRET PRODUSE
		
		lnProcDisc = Iif(oset.discount And Thisform.ct_discount1.Combogrid3.Value=3,Thisform.ct_discount1.proc_discount ,0)
		*!*	modificare	ROAFACTURARE	v 2.0.96
		If oset.id_set = 267
			lnProcDisc = 0
		Endif
		*!*	modificare	ROAFACTURARE	v 2.0.96	^
		*!*	modificare 22.06
		*!*	lnProcAdaos = IIF(oset.adaos,thisform.ct_adaos1.proc_adaos,0)
		lnProcAdaos = Iif(oset.adaos,Iif(Thisform.ct_adaos1.proc_adaos<-9999999,0,Thisform.ct_adaos1.proc_adaos),0)
		*!*	^
		
		Select cursor_curent1
		Scatter Name oStg
		
		If Empty(oStg.Cont)
			amessagebox('Nu s-a selectat niciun reper! Repetati selectia!',48,"Atentie")
			Release oStg
			Thisform.ct_grid_search1._GRID1.SetFocus
			Return
		Endif
		
		*!*	modificare	v 2.1.34
		If oset.model >= 3 And Type(Thisform.ct_grid_search1.cnumecursor+".in_stoc")<>"U"
			IF oStg.in_stoc = 0
				amessagebox("Acest articol este prezent in stoc, dar nu este definit ca fiind gestionabil!"+CHR(13)+CHR(10)+;
					"Intrati pe acest articol in 'Gestiuni > Configurare > Catalog de materiale si marfuri' si bifati casuta 'Articol gestionabil'!",48,"Atentie")
				RETURN
			ENDIF
		Endif
		*!*	modificare	v 2.1.34	^
		
		*!*	modificare	ROAGEST	v 2.1.19 :
		*!*		verific daca articolul ales respecta metoda FIFO / LIFO
		*!*	modificare	ROAGEST	v 2.1.25 : am adaugat conditia legata de oset.id_set ( ob. de inv. )
		If oset.model = 3 AND INLIST(gnFifoLifo,1,2) AND !INLIST(oset.id_set,70,72,104)
		*!*		Select Min(a.nrordine) As nrordinemin From (Thisform.ct_grid_search1.cnumecursor) a ;
		*!*			Left Join (Select Sum(cante) As cantitate From (Thisform.ct_grid_order1.cnumecursor) ;
		*!*			WITH (Buffering = .T.) Where id_articol = oStg.id_articol ;
		*!*			AND id_gestout = oStg.id_gestiune And Nvl(serie,'') = Nvl(oStg.serie,'') And datain = oStg.datain ;
		*!*			GROUP By id_articol,serie) b On 1 = 1 ;
		*!*			Where a.cantitate - Nvl(b.cantitate,0) <> 0 Into Cursor crsComparatie
			Select Min(nrordine) As nrordinemin From (Thisform.ct_grid_search1.cnumecursor) ;
				Where id_articol = oStg.id_articol ;
				AND id_gestiune = oStg.id_gestiune And Nvl(serie,'') = Nvl(oStg.serie,'') ;
				AND stoc_actual > 0 Into Cursor crsComparatie
			Select crsComparatie
			lnNrOrdineMin = nrordinemin
			If lnNrOrdineMin <> oStg.nrordine
				amessagebox("Articolul ales nu respecta metoda "+Iif(gnFifoLifo=1,"FIFO","LIFO")+" !",48,"Atentie")
				Select (Thisform.ct_grid_search1.cnumecursor)
				lnRecno = Recno()
				Locate For id_articol = oStg.id_articol ;
					AND id_gestiune = oStg.id_gestiune And Nvl(serie,'') = Nvl(oStg.serie,'') And nrordine = lnNrOrdineMin
				If !Found()
					Go lnRecno
				Endif
				Thisform.ct_grid_search1.SetFocus()
				Return
			Endif
		Endif
		*!*	modificare	ROAGEST	v 2.1.19	^
		
		*!*	If oSet.model > 2  And !Empty(NVL(oStg.id_rul_aux,0))
		*!*		amessagebox("Operatiile asupra acestui reper se pot efectua doar din programul ROAVIN!",48,"Atentie")
		*!*		Release oStg
		*!*		Thisform.ct_grid_search1._GRID1.SetFocus
		*!*		Return
		*!*	Endif
		
		*!* DNF
		Select (lcSelRul)
		Scatter Name orul BLANK MEMO 
		If !Pemstatus(orul,'dnf',5)
			AddProperty(orul,'dnf',00000)
			If Pemstatus(oStg,'dnf',5)
				orul.DNF= oStg.DNF
			Endif
		ENDIF
		
		*!* MODIFICAT 11.04.2006
		*!* MARIUS.MUTU - SA SE POATA SCOATE DIN STOC DE MAI MULTE ORI ACEEASI CANTITATE LA OB INV IN FOLOSINTA CAND TRANSFER, CASARE DIN FOLOSINTA
		*!*	SET STEP ON
		Local lnCantIesita, lnCantStoc
		lnCantIesita = 0
		lnCantStoc = 0
		If !Inlist(oset.id_set,210,211,212,89,70)
			If 'B' $ lcIde
				Sele (lcSelRul)
				If !Inlist(gnTipGest , 6,7)
					Select Sum(cante) As cante, id_articol, Nvl(serie,'') As serie From (lcSelRul) ;
						WITH (Buffering = .T.) Where id_articol = oStg.id_articol And Pret =oStg.Pret ;
						AND id_gestout = oStg.id_gestiune And Nvl(serie,'') = Nvl(oStg.serie,'') ;
						GROUP By id_articol,serie Into Cursor crsCant
					*!*			LOCATE FOR id_articol = ostg.id_articol AND pret =ostg.pret AND id_gestout = ostg.id_gestiune   && id_gestout in loc de id_gestiune pt ca la transfer modific id_gestiune (inainte_de_do_termin)
				Else
					Select Sum(cante) As cante, id_articol,Nvl(serie,'') As serie From (lcSelRul) ;
						WITH (Buffering = .T.) Where id_articol = oStg.id_articol And pretv =oStg.pretv ;
						AND id_gestout = oStg.id_gestiune And Pret =oStg.Pret And Nvl(serie,'') = Nvl(oStg.serie,'') ;
						GROUP By id_articol,serie Into Cursor crsCant
					*!*			LOCATE FOR id_articol = ostg.id_articol AND pretv =ostg.pretv AND id_gestout = ostg.id_gestiune AND pret =ostg.pret  && id_gestout in loc de id_gestiune pt ca la transfer modific id_gestiune (inainte_de_do_termin)
				Endif
				*!* 27.05.2009
				Select crsCant
				Locate
				lnCantIesita = cante
				lnCantStoc = oStg.cantitate
				If lnCantStoc <= lnCantIesita
					amessagebox('Stoc epuizat',0+64,"Info")
					Thisform.ct_grid_search1._GRID1.SetFocus
					Use In crsCant
					Return
				Endif
				*!* 27.05.2009 ^
				Use In crsCant
			Endif
		Else
			&& scoatere din stoc obiecte de inventar
			If 'B' $ lcIde
				Sele (lcSelRul)
				
				*!*	modificare	v 2.1.25 : am pus nvl la id_responsabil = oStg.id_responsabil
				Select Sum(cante) As cante, id_articol, Nvl(serie,'') As serie ;
					FROM (lcSelRul) With (Buffering = .T.) ;
					WHERE id_articol = oStg.id_articol And Pret =oStg.Pret And id_gestout = oStg.id_gestiune ;
					AND NVL(id_responsabil,0) = NVL(oStg.id_responsabil,0) And datapif = oStg.datapif And Nvl(serie,'') = Nvl(oStg.serie,'') ;
					GROUP By id_articol,serie Into Cursor crsCant
				*!* 27.05.2009
				Select crsCant
				Locate
				lnCantIesita = cante
				lnCantStoc = oStg.cantitate
				If lnCantStoc <= lnCantIesita
					amessagebox('Stoc epuizat',0+64,"Info")
					Thisform.ct_grid_search1.cb_tx_cautare1.Text.SetFocus
					Use In crsCant
					Return
				Endif
				*!* 27.05.2009 ^
				Use In crsCant
			Endif
		
		Endif
		
		*!*	modificare	03.10.2007
		If Inlist(oxset.model,4,6)	&&	Retur
			lcObiect = Thisform.cobj
			&lcObiect..id_gestout = oStg.id_gestiune
			&lcObiect..gestout = Alltrim(oStg.nume_gestiune)
		Endif
		*!*	modificare	03.10.2007	^
		
		
		Thisform.assign_values('orul',Thisform.cobj,'oStg')
		
		* La transfer, tabelul din dreapta rul_temp1 are cantitatile intrate, iar crsTransfer cantitatile iesite
		* Daca se schimba gestiunea sursa, se schimba si pcObj.id_gestiune = pcObje.id_gestout (poAct) si in rul_temp1 (intrari) va intra gestiunea sursa, in loc de destinatie
		* Modific gestiunea = gestiunea sursa in intrari
		If Inlist(oSet.model, 5) AND TYPE('orul.id_gestiune') = 'N' AND !EMPTY(NVL(pcObj.id_gestin,0)) && TRANSFER
			orul.id_gestiune = pcobj.id_gestin
			orul.nume_gestiune = pcobj.gestin
		ENDIF 
		
		
		* 01.04.2021 - repun responsabilul salvat dupa articolul anterior
		IF !EMPTY(NVL(Thisform.nIdResponsabil,0))
			orul.id_responsabil = thisform.nIdResponsabil 
			orul.nresp = thisform.nResp
		ENDIF 
		
		If Type('orul.datapif') # 'U' And Type('orul.datapif') = 'T' && pentru ob. inv. in folosinta
			orul.datapif = Ttod(orul.datapif)
		Endif
		
		If Inlist(oset.model,3,4) And oset.param1 = 1  && bon/retur + factura + en-detail
			lnPretvTva = orul.pretv + orul.tvav  && pret vanzare cu TVA
			*!*	modificare 22.06
			lnProcAdaos = Iif(orul.procent<>0,orul.procent,lnProcAdaos)
			*!*	^
		Else
			*!* 09.06.2008
			*!* 231 - nir mf pretv cu modificarea listei de preturi
			*!* 105,106 - roafacturare - NIR de marfa la pret de vanzare;
			*!* 231 = roagest - nir marfa la pretv cu lista de preturi
			*!* 236,240,241,243 - retur de la gestiune valorica - aviz expeditie - pret de lista
			*!* 247  = roagest - nir marfa la pretv cu lista de preturi gestiune hibrid 23.10.2008
			*!* 266 roagest - mf pret de ach * > factura nesosita - pret de lista ** 19.05.2010
			If Inlist(oset.id_set,105,106,231,236,240,241,242,247,255,256,266)
				lcSql = [ select pretftva, pretctva, (proc_tvav*100-100) as proc_tvav from vcrm_politici_pret_art where id_pol=] + Alltrim(Str(poact.id_pol))+;
					[ and id_articol =] + Alltrim(Str(oStg.id_articol))
		
				lnSucces=goExecutor.oExecute(lcSql,'crsPret')
				If lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,'Eroare')
				Endif
		
				Select crsPret
				lnPretfTva = pretftva
				lnPretvTva = pretctva
				IF !PEMSTATUS(poAct, 'proc_tvav',5 )
					ADDPROPERTY(poAct, 'proc_tvav', 24)
				ENDIF 
				poAct.proc_tvav = crsPret.proc_tvav
				
				Use In (SELECT('crsPret'))
		
				Private pnReturnValue
				pnReturnValue = 0
				lnSucces = goExecutor.oSelect2Value("select preturi_cu_tva from vcrm_politici_preturi where id_pol = " + Alltrim(Str(poact.id_pol)), @pnReturnValue)
				If lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,'Eroare')
				Else
					lnListaPreturiCuTva	= pnReturnValue
				Endif
			Else
				lnPretvTva = 0
			Endif
			*!* 09.06.2008
		Endif
		
		If oset.id_set = 104
			Private pnImputare
			Store 0 To pnImputare
		
			If gnImputare = 1 && pretul maxim din stoc
				lcSql=[select MAX(pret) as pretMax from (select pack_sesiune.suma_ron(pret, an, luna) as pret from ] + ;
					[(select pret, an, luna from stoc where id_articol = ] + +Alltrim(Str(orul.id_articol))+ ;
					[ and NVL(serie,'x_x_x') = '] + Nvl(orul.serie,'x_x_x') + [' ] + gcCondSucursala + [))]
		
				lnSucces=goExecutor.oExecute(lcSql,'crsPretMax')
				If lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,'Eroare')
				Endif
		
				Select crsPretMax
				orul.pretv = pretMax
				If Isnull(orul.pretv)
					orul.pretv = 0
				Endif
		
				If Used('crsPretMax')
					Use In crsPretMax
				Endif
			Endif
		Endif
		
		If Empty(Thisform.cfrm_ceredate)
			Return
		Endif
		
		If Inlist(oset.id_set,211) && TRANSFER MAGAZIE OB INV IN FOLOSINTA - CATRE GESTIUNE OB INV IN FOL PE UN RESPONSABIL
			orul.id_responsabil = 0
			orul.NRESP = ''
		Endif
		
		lcForm = Alltrim(Thisform.cfrm_ceredate)
		onir = Createobject(lcForm,Thisform.omemopref)		&&	modificare ROAGEST v 2.2.29 : am adaugat Thisform.omemopref
		onir.bVizualizare = lcIde
		onir.cobj = orul
		*onir.cParentObj = thisform.cobj
		onir.pretvtva = lnPretvTva
		*!* 27.05.2009
		onir.ncant_stoc = lnCantStoc
		onir.ncant_iesita = lnCantIesita
		*!* 27.05.2009 ^
		*!* 11.09.2008 ROAGEST 2.0.61
		*!* 105 Achizitie fact. neplatita- marfa la pret de vanzare
		*!* 106 ?
		*!* 231 Achizitie fact. neplatita- marfa la pret de vanzare - pret de lista
		*!* 234 Achizitie fact. neplatita - bilete RATC - marfa la pret de vanzare -pret de list
		*!* 236,240,241,242 - Retur de la gestiune valorica - lista preturi - aviz expeditie
		*!* 247  = roagest - nir marfa la pretv cu lista de preturi gestiune hibrid 23.10.2008
		*!* 248 Achizitie fact. neplatita - bilete RATC - marfa la pret de vanzare -pret de list - gestiune hibrid 23.10.2008
		*!* 266 roagest - mf pret de ach * > factura nesosita - pret de lista ** 19.05.2010
		If Inlist(oset.id_set,105,106,231,234,236,240,241,242,247,248,255,256,266)
			onir.cobj.pretv = lnPretfTva
			onir.cobj.tvav = lnPretvTva - lnPretfTva
		Endif
		*!* 11.09.2008 ROAGEST 2.0.61 ^
		
		If oset.model = 2 And Type('ostg.cantitate') = 'N' And oset.id_selst = 30
			onir.cobj.cant = oStg.cantitate
		Endif
		*!* 09.06.2008
		*!* 231 - nir mf pretv cu modificarea listei de preturi
		&& 247  = roagest - nir marfa la pretv cu lista de preturi gestiune hibrid 23.10.2008
		*!* 248 Achizitie fact. neplatita - bilete RATC - marfa la pret de vanzare -pret de list - gestiune hibrid 23.10.2008
		*!* 266 roagest - mf pret de ach * > factura nesosita - pret de lista ** 19.05.2010
		*!*	267	modificare	ROAFACTURARE v 2.2.2
		If Inlist(oset.id_set,231,234,236,240,241,242,247,248,255,256,266,267) OR (m.gnRG_NIR_ULTIMUL_PRET = 1 AND INLIST(oset.id_set,43,44,45,46,47,48,49,50,51,101,94,85,246,249,250,251,264))
			&& v 2.0.14 din 11iun2008 - preluare preturi din rul de pe ultima factura de achizitie/retur, cautarea se face in ultimele 2 luni
			&& 231 - NIR LISTA PRETURI
			&& 234 - NIR RATC
			*!* v 2.0.18 (ordonare an desc, luna desc, dataora desc, cant <> 0)
			*!* 11.05.2009 -ultimul pret de achizitie,vanzare este din ultimii 2 ani
			*!* 30.03.2010 - se ia si proc_tva
			*!* 13.09.2010
			If Type('gnRG_PRET_ULTIMA_INTRARE') = 'N' And gnRG_PRET_ULTIMA_INTRARE = 1
				lcSql = [select pret, tva, proc_tva, pretv, tvav, pretvtva, dataora ]+;
					[ from rul_ultima_intrare where ID_ARTICOL = ]+Alltrim(Str(orul.id_articol))
			Else
				lcSql = [select a.* from  (select a.dataora,a.pret,a.tva, a.proc_tva, a.tvav,a.pretv,a.PRETV+a.TVAV as pretvtva ]+;
					[ from rul a where a.ID_ARTICOL = ]+Alltrim(Str(orul.id_articol)) + [ and a.sters = 0 and ] + ;
					[((a.cant<>0  and a.id_tip_rulaj = 0) or (a.cante<0 and a.id_tip_rulaj = 1) )]+;
					[ and an*12+luna between ]+ Alltrim(Str(gnAn*12+gnluna-23))+[  and ]+ Alltrim(Str(gnAn*12+gnluna)) +;
					[ order by a.an desc, a.luna desc, a.dataora desc) a where rownum = 1]
			Endif
			*!* 13.09.2010 ^
			*!* v 2.0.18 ^
			lnSucces=goExecutor.oExecute(lcSql,'crsPretUltim')
			If lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,'Eroare')
			Else
				Select crsPretUltim
				If Reccount() > 0
					onir.pretu_factura = crsPretUltim.Pret
					onir.cobj.Pret = crsPretUltim.Pret
					onir.cobj.tva = crsPretUltim.tva
					onir.cobj.proc_tva = crsPretUltim.proc_tva
					&& suprascriu pretul de vanzare din lista doar daca pe nir am pretul <> 0
					*!*	267	modificare	ROAFACTURARE v 2.2.2
		*!*				If crsPretUltim.pretv <> 0 and oset.id_set <> 267
					*!* 21.12.2015 nu mai suprascriu pretul de vanzare din lista de preturi. de ce ar trebui sa il suprascriu?
					If crsPretUltim.pretv <> 0 and onir.cobj.pretv = 0 and oset.id_set <> 267
						onir.cobj.pretv = crsPretUltim.pretv
						onir.cobj.tvav = crsPretUltim.tvav
						onir.pretvtva = crsPretUltim.pretvtva
					Endif
		
				Endif
				Use In 	crsPretUltim
			Endif
			&& v 2.0.14 din 11iun2008 ^
		Endif
		
		*!* 09.06.2008 ^
		
		onir.cTitlu = Alltrim(Nvl(oStg.denumire,'')) + [-] + Alltrim(Nvl(oStg.codmat,''))
		onir.item2.text_item1.ReadOnly =  Iif(oset.model = 2, .F., .T.)
		
		If oset.param1 = 1 And (oset.model = 4 Or gnTipGest = 6 Or gnTipGest = 7) && facturi retur / vanzare marfa la pret de vanzare en-detail - blochez pretul de vanzare
			onir.BlochezPretV = .T.
			onir.proc_tvav = orul.proc_tvav
			onir.proc_adaos = lnProcAdaos
		Endif
		
		Do Case
			Case oset.model = 7  && ( oset.id_set = 218 )
				onir.item9.label_item1.Caption = 'Pret nou fara TVA'
				onir.item9.text_item1.InputMask = get_mask(12,gnPPret)
			Case poact.id_set = 104 && RoaObInv - Imputare
				onir.item7.label_item1.Caption = 'Pret imputare cu TVA'
				onir.item8.label_item1.Caption = 'TVA imputare'
				onir.item9.label_item1.Caption = 'Pret imputare fara TVA'
				* onir.BlochezPretV = .T.
			Case poact.id_set = 26001 && ROAPRODUCTIE.PV_PRODUCTIE
				Local lnPret
				Store 0 To lnPret
		
				Private poPret
				Store '' To poPret
				Local lcschema, lcselect, lcFiltru, lcOrder, llAfiseaza, lcgroup, llModParam, lcFiltruOriginal
		
				lcschema = []
				lcselect = [select pret from vcrm_politici_pret_art]
				lcOrder = []
				lcFiltru = []
				llAfiseaza = .F.
				lcgroup = ""
				llModParam = .T.
				lcFiltruOriginal = [id_pol=] + Alltrim(Str(poact.id_pol)) + [ and id_articol=] + Alltrim(Str(oStg.id_articol))
		
				gencursor('poPret','crsPret',lcselect,lcFiltru,lcschema,lcOrder,llAfiseaza, lcgroup, llModParam, lcFiltruOriginal)
				poPret.ca_baza1.afisare()
		
				Select crsPret
				Go Top
				lnPret = Pret
		
				If Used('crsPret')
					Use In crsPret
				Endif
		
				Release poPret
		
				onir.cobj.Pret = lnPret
				onir.item2.label_item1.Caption = 'Pret unitar'
				onir.item2.text_item1.ReadOnly = .T.
				onir.item2.text_item1.TabStop = .F.
		
				Local lcReteta, lnId_reteta
				Store 0 To lnId_reteta
				Store '' To lcReteta
		
				Private poReteta
				Store '' To poReteta
		
				lcschema = []
				lcselect = [select id_reteta, reteta from vnom_retetar]
				lcOrder = []
				lcFiltru = []
				llAfiseaza = .F.
				lcgroup = ""
				llModParam = .T.
				lcFiltruOriginal = [principala=1 and id_articol=] + Alltrim(Str(onir.cobj.id_articol))
				gencursor('poReteta','crsReteta',lcselect,lcFiltru,lcschema,lcOrder,llAfiseaza, lcgroup, llModParam, lcFiltruOriginal)
				poReteta.ca_baza1.afisare()
		
				Select crsReteta
				Go Top
				lcReteta = Alltrim(reteta)
				lnId_reteta = id_reteta
		
				If Used('crsReteta')
					Use In crsReteta
				Endif
		
				Release poReteta
		
				onir.cobj.reteta = lcReteta
				onir.cobj.id_reteta = lnId_reteta
		Endcase
		
		*onir.item4.text_item1.comment = onir.item4.text_item1.comment + IIF(INLIST(oset.model,3,4),[e],[]) && CANT sau CANTE
		onir.item4.text_item1.Comment = onir.item4.text_item1.Comment + ;
			Iif(Lower(Alltrim(Thisform.osel_dr.cantitate))=[cante],[e],[]) && CANT sau CANTE
		onir.proc_discount = lnProcDisc
		onir.proc_adaos = lnProcAdaos
		
		*** modific lucrarea cu lucrarea asociata gestiunii, daca este configurata
		lcSql = [select id_lucrare, nrord from vnom_gestiuni where id_gestiune = ] + alltrim(str(orul.id_gestiune))
		llSucces = goExecutor.oExecuta(m.lcSql, "crsLucrareTemp")
		if m.llSucces
			go top in crsLucrareTemp
			if !empty(nvl(crsLucrareTemp.nrord,''))
				onir.cobj.id_lucrare = crsLucrareTemp.id_lucrare
				onir.cobj.nrord = alltrim(crsLucrareTemp.nrord)
			endif 	
			use in (select('crsLucrareTemp'))
		endif 
		
		onir.Show(1)
		
		If gnButon = 1
			lcCant = [orul.] + Alltrim(Thisform.osel_dr.cantitate)
			If Type('ostg.cantitate') # 'U' And Inlist(oset.model, 3, 4, 5, 6, 7)  &&: bon, retur, transfer, retur transfer
				lnCantD = &lcCant
				lnCantD1 = &lcCant
				lnCantS = oStg.cantitate
		
				*!* MODIFICAT 11.04.2006
				*!* DOAR LA ID_SET = 210 (TRANSFER OB INV IN FOL CATRE MAI MULTI RESPONSABILI) AM PERMIS SA SE SCOATA DE MAI MULTE ORI ACELASI REPER
				*!* ADUN CANTITATEA DEJA IESITA LA CEA CURENTA
				lnCant = 0
				If Inlist(oset.id_set,210,211,212,89)
					Select Sum(Nvl(cant,0)) As cant ;
						FROM (lcSelRul) With (Buffering = .T.);
						WHERE id_articol = oStg.id_articol And Pret = oStg.Pret And ;
						id_gestout = oStg.id_gestiune And Nvl(serie,'') = Nvl(oStg.serie,'') ;
						INTO Cursor crsCant
					Select crsCant
					Calculate Sum(cant) To lnCant
					lnCantD = lnCantD + lnCant
					Use In crsCant
				Endif
				If Abs(lnCantD) > Abs(lnCantS) Or (Sign(lnCantD1) * Sign(lnCantS) < 0)
					lcTitlu = [Atentie]
					lcTip = [Avertizare]
					lcImagine = [exclam.ico]
					ofrm_eroare = Createobject('frm_mesaj',lcTitlu,lcImagine,lcTip,"Cantitatea maxima existenta este:",oStg.cantitate)
					ofrm_eroare.Show(1)
					Release ofrm_eroare
					&lcCant = oStg.cantitate - lnCant
				Endif
		
				*!* MODIFICAT 11.04.2006
				*!* NU ADAUG ARTICOLE FARA CANTITATE
				If &lcCant = 0
					Thisform.ct_grid_order1.cb_tx_gestin.SetFocus()
					Return
				Endif
			Endif
		
			Do Case
				Case Inlist(oset.model, 4, 6)  && retur BON, retur TRANSFER
					&lcCant = -&lcCant
				Case oset.model = 2 && NIR
					Select (lcSelRul)
					lcAcont = Thisform.assign_analitic(orul.Cont,Thisform.cobj,'orul')
					IF !EMPTY(m.lcAcont)
						orul.acont = m.lcAcont
					ENDIF 	
			Endcase
		
			If Inlist(oset.model,5,6,7) && TRANSFER, RETUR TRANSFER, DIFERENTA DE PRET
				lcCantDr = Lower(Alltrim(Thisform.osel_dr.cantitate))
				lcCantTransf = [cant] + Iif(lcCantDr = [cante],[],[e])
				If !Used('crsTransfer')
					Select *, 0000 As rec, 0 As nuInConturiX From (lcSelRul) Into Cursor crsTransfer Where 1=2 NOFILTER Readwrite
				Endif
				Select crsTransfer
				Append Blank
				Gather Name pcObj
				Gather Name oStg
				Replace cant With 0, cante With 0
				Replace &lcCantTransf With &lcCant
				*!* v 2.0.24
				lnProcTVA = Iif(proc_tva <> 0, proc_tva, TVA2PROCTVA(tva, Pret))
				Replace proc_tva With lnProcTVA
				*!* v 2.0.24 ^
				*REPLACE nuInConturiX WITH 1
				*!*	modificare 26.02.2007
				Do Case
					Case Inlist(oset.id_set,75,218)	&&	modificare 22.05.2007 : completez si pretv ca sa pot calcula adaosul
						Replace pretv With orul.pretv,tvav With orul.tvav,proc_tvav With orul.proc_tvav
					Case Inlist(oset.id_set, 207,254)
						orul.pretv = oStg.pretv
						orul.tvav = oStg.tvav
						orul.proc_tvav = oStg.proc_tvav
					Case oset.id_set = 89 && transfer intre persoane
						pcObj.id_gestin = orul.id_gestout
						pcObj.gestin = orul.id_gestout
						orul.id_gestin = orul.id_gestout
						orul.gestin = orul.gestout
				Endcase
				*!*			IF oset.id_set = 89 && transfer intre persoane
				*!*				pcObj.id_gestin = orul.id_gestout
				*!*				pcObj.gestin = orul.id_gestout
				*!*				orul.id_gestin = orul.id_gestout
				*!*				orul.gestin = orul.gestout
				*!*			ENDIF
				*!*	modificare 26.02.2007	^
				Replace id_gestin With orul.id_gestin, gestin With orul.gestin
				Replace id_gestout With orul.id_gestout, gestout With orul.gestout
				*!*			IF TYPE('orul.id_gestiune') = 'N' AND TYPE('crsTransfer.id_gestiunec') = 'N'
				*!*				REPLACE id_gestiunec WITH orul.id_gestiune
				*!*			ENDIF
				If Type('orul.id_responsabil') = 'N' And Type('crsTransfer.id_responsabilc') = 'N'
					Replace id_responsabilc With orul.id_responsabil
				Endif
				*!* nou 26.05.2009
				Replace id_lucrare With orul.id_lucrare, nrord With orul.nrord
				Replace id_sectie With orul.id_sectie, sectie With orul.sectie
				*!* nou 26.05.2009 ^
			Endif
		
			If oset.id_set = 104
				If gnImputare = 1
					Select cursor_curent1
					If DNF<>0
						uzura = (DNF-(dns_luni-Iif(!Empty(datapif) And !Isnull(datapif),((gnAn*12+gnluna)-(Year(datapif)*12+Month(datapif))),0)))/DNF*100
					Else
						uzura = 0
					Endif
					Do Case
						Case pnImputare = 1 && procent
							orul.pret_imputare = Round((100 - uzura) * orul.pretv / 100,gnPPretV)
						Case pnImputare = 2 && integral
							orul.pret_imputare = orul.pretv
						Otherwise
							orul.pret_imputare = orul.pretv
					Endcase
				Else
					orul.pret_imputare = orul.pretv
				Endif
			Endif
		
			Select (lcSelRul)
			Append Blank
			Gather Name orul
			Replace id_set With oset.id_set
			lnRecno = Recno()
		
			*!*		IF TYPE('ostg.id_gestiune') = 'N'
			*!*			REPLACE id_gestiunec WITH ostg.id_gestiune
			*!*		ENDIF
			If Type('ostg.id_responsabil') = 'N'
				Replace id_responsabilc With oStg.id_responsabil
			Endif
		
			*!* MODIFICAT 11.04.2006
			*!* MARIUS.MUTU - AM PUS RECNO('RUL_TEMP') IN CURSORUL DE TRANSFER - LA STERGERE SA POT STERGE SI LINIA CORESPONDENTA DIN CRSTRANSFER
			If Inlist(oset.model,5,6,7) And Used('crsTransfer') && TRANSFER, RETUR TRANSFER, DIFERENTA DE PRET
				Select crsTransfer
				Replace rec With lnRecno
			Endif
		
			*!* 09.06.2008
			*!* 231 - nir mf pretv cu modificarea listei de preturi
			*!* daca pretul de vanzare este diferit de pretul de vanzare din lista
			*!* modific pretul de vanzare din lista
			*!* 247  = roagest - nir marfa la pretv cu lista de preturi gestiune hibrid 23.10.2008
			*!* 266 roagest - mf pret de ach * > factura nesosita - pret de lista ** 19.05.2010
			If Inlist(oset.id_set, 231, 247, 266) And poPreturi.pretvtva <> lnPretvTva And lnNIRPRETLISTAMOD = 1
				lnPretftvaLista = poPreturi.pretv
				lnPretvtvaLista = poPreturi.pretvtva
				lnPretLista = Iif(lnListaPreturiCuTva = 1, lnPretvtvaLista, lnPretftvaLista)
		
				Thisform.modificare_lista_preturi(poact.id_pol, oStg.id_articol, lnPretftvaLista, lnPretvtvaLista, lnPretLista, orul.proc_tvav)
			Endif
			*!* 09.06.2008 ^
		
			*!* 10.09.2008 v 2.0.61
			*!* 236, 240, 241, 242 = retur de la gestiune valorica
			If Inlist(oset.id_set, 236, 240, 241, 242,255,256) And poPreturi.pretvtva <> lnPretvTva
				lnPretftvaLista = poPreturi.pretv
				lnPretvtvaLista = poPreturi.pretvtva
				lnPretLista = Iif(lnListaPreturiCuTva = 1, lnPretvtvaLista, lnPretftvaLista)
		
				Thisform.modificare_lista_preturi(poact.id_pol, oStg.id_articol, lnPretftvaLista, lnPretvtvaLista,lnPretLista, orul.proc_tvav,lnPretvTva)
			Endif
			*!* 10.09.2008 v 2.0.61 ^
			
			* 01.04.2021 salvez responsabilul ales de utilizator si il folosesc pentru articolele urmatoare
			thisform.nIdResponsabil = orul.id_responsabil
			thisform.nResp = orul.nresp
		
		
			If Thisform.ct_grid_order1.cb_tx_gestin.Visible
				Thisform.ct_grid_order1.cb_tx_gestin._cbbase1.Value = orul.gestin
				Thisform.ct_grid_order1.cb_tx_gestin._cbbase1.Refresh
			Endif
			Thisform.ct_grid_order1.actualizeaza_grid()
			Thisform.ct_grid_order1._GRID1.AutoFit
		Else
			Thisform.ct_grid_search1._GRID1.SetFocus
		Endif
		
		Thisform.calcul_sume(lcSelRul)
		
		*!*	SELECT crsTransfer
		*!*	BROWSE
		*!*	SELECT (lcSelRul)
		*!*	BROWSE
		
		If oset.productie And Inlist(oset.id_set,26003,26004)	&& modificare 17.10.2007	AND ALLTRIM(UPPER(oset.formproduc))='FRM_ALEGE_SECTIE_COMANDA'
			pnValoareDecontata = Thisform.nTotal
			pnCheltuieliDirecte = Thisform.nTotal - pnValoareDecontata
			Thisform.container_valoare_decontata1.Refresh
		Endif
		If Thisform.nTotal#0
			lnProcentDiscount=(Thisform.ct_discount1.baza_discount/Thisform.nTotal)*100
		Else
			lnProcentDiscount=0
		Endif
		
		If(Thisform.ct_discount1.Combogrid3.Value=2)
			Thisform.ct_discount1.txProc_discount.Value=lnProcentDiscount
		Endif
		
		*!*	modificare	ROAGEST v 2.1.19
		If oset.model = 3
			Select (Thisform.ct_grid_search1.cnumecursor)
			Replace stoc_actual With stoc_actual - orul.cante
		Endif
		*!*	modificare	ROAGEST v 2.1.19	^
		Release orul
		Release oStg
		
	ENDPROC

	PROCEDURE _shape1.DblClick
		IF thisform.WindowState = 2
			thisform.WindowState = 0
		ELSE 
			thisform.WindowState = 2 
		ENDIF 
	ENDPROC

ENDDEFINE

DEFINE CLASS nir_orig AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Ct_discount1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_shape3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_shapeDr" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_shapeSus" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Urmator1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lbTotal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="txNir" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_adaos1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.But_nou1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.lb_listePreturi" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.cboListe" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_search1.Cb_tx_gestout" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1.Cb_tx_gestin" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_grid_order1.But_sterge1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Container_valoare_decontata1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura2.lb_curs" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Ct_factura2.lb_valuta" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="tx_totalctva" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_totalctva" UniqueID="" Timestamp="" />

	#INCLUDE "..\include\foxpro.h"
	*<DefinedPropArrayMethod>
		*m: aleg_cont_transfer
		*m: analiza_cmp
		*m: assign_analitic
		*m: assign_values
		*m: bon_fiscal
		*m: calcul_pret_vanzare
		*m: calcul_sume
		*m: caut_gestiune
		*m: compensare
		*m: do_verifica_sume
		*m: intrare_produs
		*p: cfrm_ceredate
		*p: cobj
		*p: ctip_frm
		*p: ntotal
		*p: osel_dr
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 1
		cbuton3 = 
		cbuton4 = Ct_grid_order1.But_sterge1;but_reface1
		cfrm_ceredate = 
		cobj = 
		ctip_frm = NIR
		DoCreate = .T.
		Height = 572
		lactiv3 = .T.
		lactiv4 = .T.
		Name = "nir_orig"
		ntotal = 0
		osel_dr = 
		Width = 793
		WindowType = 1
		_shape1.Anchor = 11
		_shape1.Height = 30
		_shape1.Left = -1
		_shape1.Name = "_shape1"
		_shape1.Tag = ""
		_shape1.Top = -1
		_shape1.Width = 726
		_shape1.ZOrderSet = 2
		_shape2.Anchor = 9
		_shape2.Height = 29
		_shape2.Left = 724
		_shape2.Name = "_shape2"
		_shape2.Tag = "MOVABLE"
		_shape2.Top = 0
		_shape2.Width = 69
		_shape2.ZOrderSet = 4
		Lb_titlu_alb_b121.Anchor = 3
		Lb_titlu_alb_b121.FontName = "Comic Sans MS"
		Lb_titlu_alb_b121.FontSize = 10
		Lb_titlu_alb_b121.Height = 20
		Lb_titlu_alb_b121.Left = 10
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 5
		Lb_titlu_alb_b121.Top = 3
		Lb_titlu_alb_b121.Width = 41
		Lb_titlu_alb_b121.ZOrderSet = 8
		BUT_TERMIN1.Anchor = 9
		BUT_TERMIN1.Height = 27
		BUT_TERMIN1.Left = 757
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 3
		BUT_TERMIN1.Tag = ""
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.Width = 32
		BUT_TERMIN1.ZOrderSet = 12
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT '_shape3' AS _shape WITH ;
		Anchor = 135, ;
		BackStyle = 0, ;
		BorderColor = 7,118,177, ;
		BorderWidth = 2, ;
		Height = 427, ;
		Left = 9, ;
		Name = "_shape3", ;
		Tag = "", ;
		Top = 137, ;
		Width = 361, ;
		ZOrderSet = 1
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT '_shapeDr' AS _shape WITH ;
		Anchor = 45, ;
		BackStyle = 0, ;
		BorderColor = 7,118,177, ;
		BorderWidth = 2, ;
		Height = 427, ;
		Left = 406, ;
		Name = "_shapeDr", ;
		Tag = "", ;
		Top = 137, ;
		Width = 381, ;
		ZOrderSet = 3
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT '_shapeSus' AS _shape WITH ;
		Anchor = 11, ;
		BackStyle = 0, ;
		BorderColor = 7,118,177, ;
		BorderWidth = 2, ;
		Height = 103, ;
		Left = 8, ;
		Name = "_shapeSus", ;
		Tag = "RESIZABLE, MOVABLE", ;
		Top = 32, ;
		Width = 780, ;
		ZOrderSet = 5
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Anchor = 9, ;
		Left = 727, ;
		Name = "But_renunt1", ;
		TabIndex = 4, ;
		Tag = "", ;
		Top = 1, ;
		ZOrderSet = 7
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Container_valoare_decontata1' AS container_valoare_decontata WITH ;
		Left = 12, ;
		Name = "Container_valoare_decontata1", ;
		Top = 81, ;
		Visible = .F., ;
		ZOrderSet = 18, ;
		Label1.Name = "Label1", ;
		Text1.Name = "Text1"
		*< END OBJECT: ClassLib="ointroduceri.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_adaos1' AS ct_adaos WITH ;
		Anchor = 161, ;
		Left = 556, ;
		Name = "Ct_adaos1", ;
		TabIndex = 8, ;
		Tag = "", ;
		Top = 38, ;
		ZOrderSet = 13, ;
		LBBAZA_ADAOS.Name = "LBBAZA_ADAOS", ;
		LBTVA_ADAOS.Name = "LBTVA_ADAOS", ;
		LBPROC_ADAOS.Name = "LBPROC_ADAOS", ;
		TXBAZA_ADAOS.Name = "TXBAZA_ADAOS", ;
		TXTVA_ADAOS.Name = "TXTVA_ADAOS", ;
		TXPROC_ADAOS.Name = "TXPROC_ADAOS"
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_discount1' AS ct_discount WITH ;
		Anchor = 161, ;
		Left = 262, ;
		Name = "Ct_discount1", ;
		TabIndex = 10, ;
		Tag = "", ;
		Top = 37, ;
		ZOrderSet = 0, ;
		COMBOGRID3.Name = "COMBOGRID3", ;
		LBBAZA_DISCOUNT.Name = "LBBAZA_DISCOUNT", ;
		LBTVA_DISCOUNT.Name = "LBTVA_DISCOUNT", ;
		LBPROC_DISCOUNT.Name = "LBPROC_DISCOUNT", ;
		TXBAZA_DISCOUNT.Name = "TXBAZA_DISCOUNT", ;
		TXTVA_DISCOUNT.Name = "TXTVA_DISCOUNT", ;
		TXPROC_DISCOUNT.Name = "TXPROC_DISCOUNT", ;
		CotaTVA.HideSelection = .F., ;
		CotaTVA.Name = "CotaTVA", ;
		lbTva.Name = "lbTva", ;
		lb_explicatie_tva.Name = "lb_explicatie_tva"
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_factura1' AS ct_factura WITH ;
		Anchor = 131, ;
		Left = 14, ;
		Name = "Ct_factura1", ;
		TabIndex = 9, ;
		Tag = "", ;
		Top = 61, ;
		ZOrderSet = 14, ;
		lbBaza.Name = "lbBaza", ;
		lbTva.Name = "lbTva", ;
		txBaza.Name = "txBaza", ;
		txTva.Name = "txTva", ;
		lbExplic.Name = "lbExplic", ;
		txTotal.Name = "txTotal", ;
		lbTotal.Name = "lbTotal"
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_factura2' AS ct_factura WITH ;
		Anchor = 131, ;
		Height = 96, ;
		Left = 260, ;
		Name = "Ct_factura2", ;
		TabIndex = 9, ;
		Tag = "", ;
		Top = 36, ;
		Width = 238, ;
		ZOrderSet = 19, ;
		LBBAZA.Left = 51, ;
		LBBAZA.Name = "LBBAZA", ;
		LBBAZA.Top = 52, ;
		LBTVA.Left = 51, ;
		LBTVA.Name = "LBTVA", ;
		LBTVA.Top = 72, ;
		TXBAZA.InputMask = (get_mask(14,gnPVal)), ;
		TXBAZA.Left = 130, ;
		TXBAZA.Name = "TXBAZA", ;
		TXBAZA.Top = 50, ;
		TXTVA.InputMask = (get_mask(14,gnPVal)), ;
		TXTVA.Left = 130, ;
		TXTVA.Name = "TXTVA", ;
		TXTVA.Top = 70, ;
		LBEXPLIC.Left = 1, ;
		LBEXPLIC.Name = "LBEXPLIC", ;
		LBEXPLIC.Top = 52, ;
		TXTOTAL.ControlSource = "this.parent.totctva", ;
		TXTOTAL.InputMask = (get_mask(14,gnPVal)), ;
		TXTOTAL.Left = 130, ;
		TXTOTAL.Name = "TXTOTAL", ;
		TXTOTAL.Top = 28, ;
		LBTOTAL.Height = 17, ;
		LBTOTAL.Left = 3, ;
		LBTOTAL.Name = "LBTOTAL", ;
		LBTOTAL.Top = 19, ;
		LBTOTAL.Width = 97
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_factura2.lb_curs' AS lb_titlu_albastru_b12 WITH ;
		Alignment = 2, ;
		AutoSize = .F., ;
		Caption = "[Curs]", ;
		FontBold = .T., ;
		Height = 22, ;
		Left = 19, ;
		Name = "lb_curs", ;
		Top = 2, ;
		Width = 201
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'Ct_factura2.lb_valuta' AS lb_titlu_albastru_b12 WITH ;
		Caption = "[Valuta]", ;
		FontBold = .F., ;
		FontSize = 9, ;
		ForeColor = 7,118,177, ;
		Height = 17, ;
		Left = 58, ;
		Name = "lb_valuta", ;
		Top = 35, ;
		Width = 42
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'Ct_grid_order1' AS ct_grid_order WITH ;
		Anchor = 45, ;
		cnumecursor = rul_temp1, ;
		Height = 425, ;
		Left = 409, ;
		Name = "Ct_grid_order1", ;
		TabIndex = 11, ;
		Top = 139, ;
		Width = 375, ;
		ZOrderSet = 16, ;
		_GRID1.Height = 345, ;
		_GRID1.Left = 6, ;
		_GRID1.Name = "_GRID1", ;
		_GRID1.TabIndex = 2, ;
		_GRID1.Top = 73, ;
		_GRID1.Width = 364, ;
		Titlu.Left = 9, ;
		Titlu.Name = "Titlu", ;
		Titlu.TabIndex = 3, ;
		Titlu.Top = 3, ;
		Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Cb_tx_cautare1.Left = 7, ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.TabIndex = 1, ;
		Cb_tx_cautare1.Text.Name = "Text", ;
		Cb_tx_cautare1.Top = 46
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_order1.But_sterge1' AS but_sterge WITH ;
		Anchor = 9, ;
		Left = 310, ;
		Name = "But_sterge1", ;
		TabIndex = 5, ;
		TabStop = .F., ;
		Top = 45, ;
		Visible = .T.
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_grid_order1.Cb_tx_gestin' AS cb_tx_simplu WITH ;
		BackStyle = 0, ;
		BorderColor = 255,255,255, ;
		Height = 24, ;
		Left = 7, ;
		Name = "Cb_tx_gestin", ;
		TabIndex = 4, ;
		Top = 20, ;
		Width = 366, ;
		_CBBASE1.BorderStyle = 0, ;
		_CBBASE1.ColumnCount = 2, ;
		_CBBASE1.ColumnLines = .F., ;
		_CBBASE1.ColumnWidths = "220,40", ;
		_CBBASE1.ControlSource = "poact.gestin", ;
		_CBBASE1.FontItalic = .F., ;
		_CBBASE1.FontName = "Arial Narrow", ;
		_CBBASE1.Height = 23, ;
		_CBBASE1.Left = 124, ;
		_CBBASE1.Name = "_CBBASE1", ;
		_CBBASE1.RowSource = "nom_gestiuni.nume_gestiune,cgest", ;
		_CBBASE1.RowSourceType = 6, ;
		_CBBASE1.Sorted = .F., ;
		_CBBASE1.Top = 0, ;
		_CBBASE1.Width = 237, ;
		_LBBASE1.Caption = "gestiune destinatie:", ;
		_LBBASE1.FontItalic = .T., ;
		_LBBASE1.Left = 3, ;
		_LBBASE1.Name = "_LBBASE1", ;
		_LBBASE1.Top = 4
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search1' AS ct_grid_search WITH ;
		Anchor = 135, ;
		cnumecursor = cursor_curent1, ;
		Height = 425, ;
		Left = 11, ;
		Name = "Ct_grid_search1", ;
		TabIndex = 1, ;
		Top = 139, ;
		Width = 357, ;
		ZOrderSet = 15, ;
		_GRID1.Comment = "grd_st", ;
		_GRID1.FontName = "Arial Narrow", ;
		_GRID1.Height = 345, ;
		_GRID1.Left = 6, ;
		_GRID1.Name = "_GRID1", ;
		_GRID1.RecordSource = "cursor_curent", ;
		_GRID1.TabIndex = 3, ;
		_GRID1.Top = 73, ;
		_GRID1.Width = 347, ;
		_GRID1.ZOrderSet = 0, ;
		Titlu.Left = 9, ;
		Titlu.Name = "Titlu", ;
		Titlu.TabIndex = 4, ;
		Titlu.Top = 2, ;
		Titlu.ZOrderSet = 1, ;
		Cb_tx_cautare1.Criteriu.Comment = "criteriu_st", ;
		Cb_tx_cautare1.Criteriu.Name = "Criteriu", ;
		Cb_tx_cautare1.Height = 27, ;
		Cb_tx_cautare1.Left = 7, ;
		Cb_tx_cautare1.Name = "Cb_tx_cautare1", ;
		Cb_tx_cautare1.TabIndex = 2, ;
		Cb_tx_cautare1.Text.Comment = "text_st", ;
		Cb_tx_cautare1.Text.Height = 25, ;
		Cb_tx_cautare1.Text.Left = 103, ;
		Cb_tx_cautare1.Text.Name = "Text", ;
		Cb_tx_cautare1.Text.Top = 1, ;
		Cb_tx_cautare1.Text.Width = 207, ;
		Cb_tx_cautare1.Top = 46, ;
		Cb_tx_cautare1.Width = 312, ;
		Cb_tx_cautare1.ZOrderSet = 2
		*< END OBJECT: ClassLib="ferestre_cere_date.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search1.But_nou1' AS but_nou WITH ;
		Anchor = 9, ;
		Height = 27, ;
		Left = 322, ;
		Name = "But_nou1", ;
		TabIndex = 6, ;
		TabStop = .F., ;
		Top = 45, ;
		ZOrderSet = 3
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Ct_grid_search1.Cb_tx_gestout' AS cb_tx_simplu WITH ;
		BackStyle = 0, ;
		BorderColor = 255,255,255, ;
		Height = 24, ;
		Left = 7, ;
		Name = "Cb_tx_gestout", ;
		TabIndex = 5, ;
		Top = 20, ;
		Width = 346, ;
		ZOrderSet = 6, ;
		_CBBASE1.BorderStyle = 0, ;
		_CBBASE1.ColumnCount = 2, ;
		_CBBASE1.ColumnLines = .F., ;
		_CBBASE1.ColumnWidths = "180,30", ;
		_CBBASE1.ControlSource = "poact.gestout", ;
		_CBBASE1.FontItalic = .F., ;
		_CBBASE1.FontName = "Arial Narrow", ;
		_CBBASE1.Height = 23, ;
		_CBBASE1.Left = 101, ;
		_CBBASE1.Name = "_CBBASE1", ;
		_CBBASE1.RowSource = "nom_gestiuni.nume_gestiune,cgest", ;
		_CBBASE1.RowSourceType = 6, ;
		_CBBASE1.Sorted = .F., ;
		_CBBASE1.Top = 1, ;
		_CBBASE1.Width = 243, ;
		_LBBASE1.Caption = "Gestiune sursa", ;
		_LBBASE1.FontItalic = .T., ;
		_LBBASE1.Left = 3, ;
		_LBBASE1.Name = "_LBBASE1", ;
		_LBBASE1.Top = 3
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Ct_grid_search1.cboListe' AS combobox WITH ;
		Anchor = 3, ;
		BorderStyle = 0, ;
		ColumnCount = 4, ;
		ColumnLines = .F., ;
		ColumnWidths = "200,65,60,0", ;
		Format = "", ;
		Height = 23, ;
		Left = 104, ;
		Name = "cboListe", ;
		RowSource = "cListePret.nume_lista_preturi,datai,datas,id_pol", ;
		RowSourceType = 2, ;
		Style = 2, ;
		TabIndex = 1, ;
		Top = 21, ;
		Visible = .F., ;
		Width = 247, ;
		ZOrderSet = 5
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'Ct_grid_search1.lb_listePreturi' AS label WITH ;
		Anchor = 3, ;
		BackStyle = 0, ;
		Caption = "Lista de preturi:", ;
		FontItalic = .T., ;
		Height = 17, ;
		Left = 11, ;
		Name = "lb_listePreturi", ;
		TabIndex = 7, ;
		Top = 25, ;
		Visible = .F., ;
		Width = 84, ;
		ZOrderSet = 4
		*< END OBJECT: BaseClass="label" />

	ADD OBJECT 'lb_totalctva' AS lb_simplu WITH ;
		Anchor = 41, ;
		Caption = "Total val.vanz. cu TVA", ;
		ForeColor = 7,118,177, ;
		Left = 558, ;
		Name = "lb_totalctva", ;
		Top = 109, ;
		Visible = .F.
		*< END OBJECT: ClassLib="lb.vcx" BaseClass="label" />

	ADD OBJECT 'lbTotal' AS titlufrumos WITH ;
		Anchor = 3, ;
		AutoSize = .T., ;
		Caption = "TOTAL NIR:", ;
		ForeColor = 7,118,177, ;
		Height = 20, ;
		Left = 20, ;
		Name = "lbTotal", ;
		TabIndex = 6, ;
		Top = 40, ;
		Width = 77, ;
		ZOrderSet = 10
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="label" />

	ADD OBJECT 'tx_totalctva' AS _txbase WITH ;
		Alignment = 3, ;
		Anchor = 161, ;
		FontName = "Comic Sans MS", ;
		Height = 20, ;
		InputMask = (get_mask(12,gnPa)), ;
		Left = 678, ;
		Name = "tx_totalctva", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		TabStop = .F., ;
		Top = 107, ;
		Value = 0, ;
		Visible = .F.
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'txNir' AS _txbase WITH ;
		Anchor = 3, ;
		BackStyle = 1, ;
		ControlSource = "thisform.ntotal", ;
		DisabledBackColor = 255,255,255, ;
		FontName = "Comic Sans MS", ;
		Height = 21, ;
		InputMask = (get_mask(12,gnPA)), ;
		Left = 98, ;
		Name = "txNir", ;
		ReadOnly = .T., ;
		SpecialEffect = 1, ;
		TabIndex = 7, ;
		Tag = "", ;
		Top = 39, ;
		Width = 152, ;
		ZOrderSet = 11
		*< END OBJECT: ClassLib="_tx_base.vcx" BaseClass="textbox" />

	ADD OBJECT 'Urmator1' AS urmator WITH ;
		Anchor = 240, ;
		Left = 373, ;
		Name = "Urmator1", ;
		TabIndex = 2, ;
		Tag = "", ;
		Top = 324, ;
		ZOrderSet = 9, ;
		Imbuton1.Height = 27, ;
		Imbuton1.Name = "Imbuton1", ;
		Imbuton1.Width = 30, ;
		Command1.Name = "Command1"
		*< END OBJECT: ClassLib="baza.vcx" BaseClass="container" />
	
	PROCEDURE Activate
		this.WindowState = 2
	ENDPROC

	PROCEDURE aleg_cont_transfer
		PARAMETERS tnIdGest
		lcSql = [select (case when p.explicatie is null then s.explicatie else p.explicatie end) as explicatie,] +;
				[c.cont, p.acont from VCORESP_CONT_TIPGEST c ] +; 
				[left join vplcont_analitic p on c.cont = p.cont and p.an = ?gnAn ] +;
				[left join vplcont_sintetic s on c.cont = s.cont and s.an = ?gnAn]
		
		pcFiltruOrig = [c.id_tipgest in (select nr_pag from  vnom_gestiuni where id_gestiune = ?tnIdGest)] 
		pcfiltru = [1=2]
		pcschema = []
		pcorder = [cont,acont]
		pccoloane = [cont,acont,explicatie]
		pcTitlu = [Alegeti Contul de Transfer] 
		pcTitluColoane = [Cont,Analitic,Explicatie cont]
		locauta = cauta_alfa(lcSql,pcfiltru,pcschema,pcorder,pccoloane,pcTitlu,pcTitluColoane,'',.F.,pcFiltruOrig)		&& 11.07.2007
			
		RETURN loCauta
	ENDPROC

	PROCEDURE analiza_cmp
		PARAMETERS tcRul, tcAct
		
		*!* 14.10.2006
		*!* mutu.marius
		*!* tratare achizitie articol cu mai multe preturi
		
		LOCAL lcSql, lcCursor, lnSucces
		PRIVATE poArticol
		*** alocare numar NIR pt rulajele generate de CMP
		
		*** dezaloc in caz ca trece de mai multe ori prin metoda asta
		IF THISFORM.numar_plaja1.id_numar # 0
			THISFORM.numar_plaja1.dezalocare_numar()
		ENDIF
		
		lnIdEnt = 0
		THIS.numar_plaja1.id_entitate = lnIdEnt
		THIS.numar_plaja1.tip = 4 && NIR PT CMP
		THIS.numar_plaja1.serie = 2 && Asa transmit paramerii la procedura viz_config_serii din oproceduri_configurare.prg
		THIS.numar_plaja1.alocare_numar()
		lnNnir = THIS.numar_plaja1.numar_curent
		***
		
		SELECT * ;
			FROM (tcRul) WITH (BUFFERING = .T.) ;
			INTO CURSOR crsTempRul
		
		SELECT DISTINCT ID_ARTICOL, CONT FROM crsTempRul ;
			INTO CURSOR crsArticoleTemp
		
		&& pentru fiecare articol - se poate sa am acelasi articol cu mai multe preturi
		SELECT crsArticoleTemp
		SCAN
			SCATTER NAME poArticol
		
			&& selectez din stoc cantitatea si pretul existente pentru articolul curent
			&& posibil mai multe gestiuni ???
			lcSql = [SELECT cants+cant-cante as cante, pret, id_articol, id_gestiune, id_gestiune as id_gestout, cont,] + ;
				[acont FROM stoc where an = ?gnAn and luna = ?gnluna and id_articol = ?poArticol.id_articol ] + ;
				[and (cants+cant-cante)<>0 and TRIM(cont) = ?ALLTRIM(poArticol.cont)] + gcCondSucursala
			lcCursorStoc = [tmpVer]
			lnSucces = goExecutor.oExecute(lcSql, lcCursorStoc)
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
				RETURN
			ENDIF
		
			&& pentru fiecare pozitie articol achizitionat din articolul curent
			SELECT crsTempRul
			SCAN FOR cant <> 0 AND id_articol = poArticol.id_articol
				SCATTER NAME orul
		
				&& scot articolul curent din rulaj la pretul de achizitie
		*!*		IF RECCOUNT(lcCursorStoc) > 0
				&& il scot chiar daca nu il am in stoc - pentru ca s-ar putea sa fie achizitionat cu mai multe preturi
					SELECT (tcRul)
					APPEND BLANK
					GATHER NAME orul
					REPLACE cante WITH orul.cant, cant WITH 0, nnir WITH lnNnir, tva WITH 0
					REPLACE id_tip_rulaj WITH 2 && RULAJ ARTIFICIAL CMP
		*!*		ENDIF
		
				SELECT crsTempRul
			ENDSCAN
		
		
			*** scot din stoc articolul curent - cantitatea si pretul existente - inainte de achizitia curenta
			IF USED(lcCursorStoc)
				SELECT (lcCursorStoc)
				SCAN
					SCATTER NAME ointr
					SELECT (tcRul)
					APPEND BLANK
					GATHER NAME orul
					REPLACE cant WITH 0, cante WITH 0
					GATHER NAME ointr
					REPLACE nnir WITH lnNnir
					REPLACE id_tip_rulaj WITH 2 && RULAJ ARTIFICIAL CMP
					SELECT (lcCursorStoc)
				ENDSCAN
				USE IN (lcCursorStoc)
			ENDIF 	
		
			&& aflu pretul mediu ponderat - selectez toate iesirile din rul_temp (articolele achizitionate si stocul precedent)
			&& pentru articol, cont curente
			&& un singur pret mediu ponderat pe articol, indiferent de gestiune
			*!* 05.12.2006
			*!* MARIUS.MUTU
			*!* LA RETUR FACTURA FURNIZOR CANTITATE NEGATIVA, DACA E RETUR LA TOATA CANTITATEA DIN STOC,  
			*!* CANTITATEA TOTALA = 0, NUMERIC OVERFLOW LA CALCUL CMP
			*!* AM FACUT ABS(CANTE)
			SELECT SUM(ROUND(PRET*ABS(cante),gnPc)) AS valoare, SUM(ABS(cante)) AS cantitate, ID_ARTICOL, CONT ;
				FROM (tcRul) WITH (BUFFERING = .T.) ;
				WHERE cante <> 0 AND ID_ARTICOL = poArticol.ID_ARTICOL  AND CONT = poArticol.CONT ;
				GROUP BY ID_ARTICOL, CONT ;
				INTO CURSOR tCmp
		
		 
			SELECT tCmp
			SCAN
				SCATTER NAME ocmp
				&& pretul mediu ponderat
				lnCMP = ROUND(ocmp.valoare/ocmp.cantitate, gnPpret)
				
				&& articol, gestiune, cantitate_totala (cantitate achizitionata cu toate preturile + stoc)
				SELECT id_articol, id_gestiune, SUM(cante) AS cant ;
					FROM (tcRul) WITH (BUFFERING = .T.) ;
					WHERE ID_ARTICOL = ocmp.ID_ARTICOL AND cante <> 0 AND CONT = ocmp.CONT ;
					GROUP BY id_gestiune, ID_ARTICOL ;
					INTO CURSOR crsCantGest
		
				&& adaug in rulaj intrarea cu toata cantitatea (achizitionata + stoc) la noul pret mediu ponderat
				SELECT crsCantGest
				SCAN
					SCATTER NAME ocant
					SELECT (tcRul)
					APPEND BLANK
					GATHER NAME orul
					REPLACE PRET WITH lnCMP, cant WITH 0, cante WITH 0, tva WITH 0
					GATHER NAME ocant
					REPLACE nnir WITH lnNnir
					REPLACE id_tip_rulaj WITH 2 && RULAJ ARTIFICIAL CMP
					SELECT crsCantGest
				ENDSCAN
				USE IN crsCantGest
				
				&& diferente de pret din rotunjiri
				IF ROUND(lnCMP * ocmp.cantitate, gnPc) - ocmp.valoare <> 0
					SELECT (tcAct)
					APPEND BLANK
					GATHER NAME poact
					REPLACE nnir WITH lnNnir
					REPLACE scd WITH ocmp.CONT, scc WITH IIF(LEFT(ocmp.cont,3) = '371', '378', '308'), ascd WITH '', ascc WITH ''
					REPLACE suma WITH ROUND(lnCMP*ocmp.cantitate,gnPc) - ocmp.valoare		
				ENDIF
				
				SELECT tCmp
			ENDSCAN
			
			USE IN tCmp
		ENDSCAN && 	crsArticoleTemp
		USE IN crsArticoleTemp
		
		SELECT (tcRul)
		
		&& program vechi
		
		*!*	PARAMETERS tcRul, tcAct
		
		*!*	*** alocare numar NIR pt rulajele generate de CMP
		
		*!*		*** dezaloc in caz ca trece de mai multe ori prin metoda asta
		*!*	IF thisform.numar_plaja1.id_numar # 0
		*!*		thisform.numar_plaja1.dezalocare_numar()
		*!*	ENDIF 
		
		*!*	lnIdEnt = 0
		*!*	this.numar_plaja1.id_entitate = lnIdEnt
		*!*	this.numar_plaja1.tip = 4 && NIR PT CMP
		*!*	this.numar_plaja1.serie = 2 && Asa transmit paramerii la procedura viz_config_serii din oproceduri_configurare.prg
		*!*	this.numar_plaja1.alocare_numar()
		*!*	lnNnir = this.numar_plaja1.numar_curent 
		*!*	*** 
		
		*!*	SELECT * FROM (tcRul) WITH (BUFFERING = .T.) INTO CURSOR crsTempRul
		*!*	SELECT crsTempRul
		*!*	SCAN FOR cant <> 0
		*!*		SCATTER NAME orul
		*!*		lcCont = ALLTRIM(orul.cont)
		*!*		lcsql = [SELECT cants+cant-cante as cante, pret, id_articol, id_gestiune, id_gestiune as id_gestout, cont, acont FROM stoc where an = ?gnAn and luna = ?gnluna and id_articol = ?orul.id_articol and (cants+cant-cante)<>0 and TRIM(cont) =?lcCont]
		*!*		lcCursor = [tmpVer]
		*!*		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		*!*		If lnSucces < 0
		*!*			amessagebox(goExecutor.cEroare,0+16,"Eroare")
		*!*			Return
		*!*		ENDIF
		*!*		IF RECCOUNT(lcCursor) > 0
		*!*			SELECT (tcRul)
		*!*			APPEND BLANK 
		*!*			GATHER NAME orul
		*!*			REPLACE cante WITH orul.cant, cant WITH 0, nnir WITH lnNnir
		*!*		ENDIF 
		*!*		SELECT (lcCursor)
		*!*		SCAN 
		*!*			SCATTER NAME ointr
		*!*			SELECT (tcRul)
		*!*			APPEND BLANK 
		*!*			GATHER NAME orul
		*!*			REPLACE cant WITH 0, cante WITH 0
		*!*			GATHER NAME ointr
		*!*			REPLACE nnir WITH lnNnir
		*!*			SELECT (lcCursor)
		*!*		ENDSCAN 
		*!*		USE IN (lcCursor)
		*!*		
		*!*	*!*		SELECT (tcRul)
		*!*	*!*		LOCATE 
		
		*!*		&& aflu pretul mediu ponderat
		*!*		SELECT SUM(ROUND(pret*cante,gnPc)) as valoare, SUM(cante) as cantitate, id_articol, cont ;
		*!*			FROM (tcRul) WITH (BUFFERING = .T.) ;
		*!*			WHERE cante <> 0 AND id_articol = orul.id_articol ;
		*!*			GROUP BY id_articol, cont ;
		*!*			INTO CURSOR tCmp
		*!*			
		*!*		SELECT tCmp
		*!*		SCAN 
		*!*			SCATTER NAME ocmp
		*!*			lnCMP = ROUND(ocmp.valoare/ocmp.cantitate,gnPc)
		*!*			
		*!*			SELECT id_gestiune, SUM(cante) as cant FROM (tcRul) WITH (BUFFERING = .T.) ;
		*!*			WHERE id_articol = ocmp.id_articol AND cante <> 0 AND cont = ocmp.cont ;
		*!*			GROUP BY id_gestiune, id_articol ;
		*!*			INTO CURSOR crsCantGest
		*!*			
		*!*			SELECT crsCantGest 
		*!*			SCAN 
		*!*				SCATTER NAME ocant
		*!*				SELECT (tcRul)
		*!*				APPEND BLANK
		*!*				GATHER NAME orul
		*!*				REPLACE pret WITH lnCMP, cant WITH 0, cante WITH 0
		*!*				GATHER NAME ocant
		*!*				REPLACE nnir WITH lnNnir
		*!*				SELECT crsCantGest 
		*!*			ENDSCAN 
		*!*			USE IN crsCantGest 
		*!*			IF ROUND(lnCMP*ocmp.cantitate,gnPc) - ocmp.valoare <> 0
		*!*				SELECT (tcAct)
		*!*				APPEND BLANK
		*!*				GATHER NAME poact
		*!*				REPLACE nnir WITH lnNnir
		*!*				REPLACE scd WITH ocmp.cont, scc WITH '308 ', ascd WITH '', ascc WITH ''
		*!*				REPLACE suma WITH ROUND(lnCMP*ocmp.cantitate,gnPc) - ocmp.valoare
		*!*			ENDIF 
		*!*			SELECT tCmp
		*!*		ENDSCAN 
		*!*		USE IN tCmp
		*!*		SELECT crsTempRul
		*!*	ENDSCAN 
		*!*	USE IN crsTempRul
		
		*!*	SELECT (tcRul)
	ENDPROC

	PROCEDURE assign_analitic
		PARAMETERS tcCont,pcAct,pcRul
		
		PRIVATE pcCont,pcAct,pcRul,pParamP,pParamS
		STORE 0 TO pParamP,pParamS
		lcAnalitic = ''
		lcAlias = ALIAS()
		
		pcCont = ALLTRIM(tcCont)
		
		lcSel = [SELECT * from ] + gcs + [.config_analitice WHERE cont = '] + ALLTRIM(pcCont) + [']
		lcCursor = 'crs_cfg_ana'
		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		IF lnSucces < 0
			aMESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
		ENDIF 
		
		IF lnSucces > 0
			IF RECCOUNT('crs_cfg_ana')=0
				USE IN crs_cfg_ana
				lnSucces = -1
			ENDIF 
		ENDIF 
		
		IF lnSucces > 0
			SELECT crs_cfg_ana
			SCATTER NAME ocfg
			lcCampPrefix = NVL(ALLTRIM(ocfg.camp_leg_prefix),'')
			lcCampSufix = NVL(ALLTRIM(ocfg.camp_leg_sufix),'')
			
			IF !EMPTY(lcCampPrefix)
				IF TYPE('&pcRul..'+lcCampPrefix) # 'U'
					pParamP = &pcRul..&lcCampPrefix
				ELSE 
					IF TYPE('&pcAct..'+lcCampPrefix) # 'U'
						pParamP = &pcAct..&lcCampPrefix
					ENDIF 
				ENDIF 
			ENDIF 
			
			IF !EMPTY(lcCampSufix)
				IF TYPE('&pcRul..'+lcCampSufix) # 'U'
					pParamS = &pcRul..&lcCampSufix 
				ELSE 
					IF TYPE('&pcAct..'+lcCampSufix) # 'U'
						pParamS = &pcAct..&lcCampSufix 
					ENDIF 
				ENDIF 
			ENDIF 
		
			lcSel = [{call fconturi_analitice('] + ALLTRIM(gcs) + [','] + ALLTRIM(pcCont) + [',0,] + TRANSFORM(pParamP) + [,] + TRANSFORM(pParamS) + [)}]
			lcCursor = 'crs_analitice'
			lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			ENDIF 
		ENDIF 
		
		&& iau Primul Simbol Analitic din Tabel - ordonat pt ca e selectat cu Distinct
		IF lnSucces > 0
			SELECT crs_analitice
			GO top
			lcAnalitic = ALLTRIM(acont)
		ENDIF 
		
		&& verificare analiticului cu Planul de Conturi
		IF lnSucces > 0
			lcSel = [SELECT cont,acont from ] + gcs + [.vplcont_analitic WHERE cont = '] + ALLTRIM(pcCont) + [' and acont = '] + ALLTRIM(lcAnalitic) +  [' and an = ] + TRANSFORM(gnAn)
			lcCursor = 'crs_verific'
			lnSucces = goExecutor.oExecute(lcSel,lcCursor)
			IF lnSucces < 0
				amessagebox(goExecutor.cEroare,0+16,"Eroare")
			ENDIF 
		ENDIF 
		
		IF lnSucces > 0
			IF RECCOUNT('crs_verific')=0
				lnSucces = -1
			ENDIF 
		ENDIF 
		
		IF USED('crs_cfg_ana')
			USE IN crs_cfg_ana
		ENDIF 
		IF USED('crs_verific')
			USE IN crs_verific
		ENDIF 
		IF USED('crs_analitice')
			USE IN crs_analitice
		ENDIF 
		IF USED('crs_verific')
			USE IN crs_verific
		ENDIF 
		
		IF lnSucces < 0
			lcAnalitic = ''
		ENDIF 
		
		SELECT (lcAlias)
		RETURN lcAnalitic
		
	ENDPROC

	PROCEDURE assign_values
		PARAMETERS tcObjDestinatie, tcObjSursa1, tcObjSursa2
		
		lcSelRul = this.ct_grid_order1.cnumecursor 
		
		lcOdest = ALLTRIM(tcObjDestinatie)
		lcOsursa1 = ALLTRIM(tcObjSursa1)
		lcOsursa2 = ALLTRIM(tcObjSursa2)
		
		SELECT (lcSelRul)
		FOR i = 1 TO FCOUNT()
			lcNumeCol = FIELD(i)
			IF TYPE('&lcOsursa1..'+lcNumeCol) # 'U'
				&lcodest..&lcNumeCol = &lcosursa1..&lcNumeCol
			ENDIF 
			IF TYPE('&lcOsursa2..'+lcNumeCol) # 'U'
				IF EMPTY(&lcodest..&lcNumeCol)
					&lcodest..&lcNumeCol = &lcosursa2..&lcNumeCol
				ENDIF 
			ENDIF 
		ENDFOR 
		
		
		
		
		
		 
	ENDPROC

	PROCEDURE bon_fiscal
		PRIVATE pnSumaMp500
		
		pnSumaMp500 = thisform.ct_factura1.txTotal.Value 
		
		ocasamp500 = CREATEOBJECT('frm_tichete',pnSumaMp500)
		ocasamp500.show(1)
		RELEASE ocasamp500
		
	ENDPROC

	PROCEDURE calcul_pret_vanzare
		PARAMETERS tcTabel
		
		LOCAL lnPretv, lnTvav, lnCoefAdaos, lnSuma, lcTabel
		STORE 0 TO lnPretv, lnTvav, lnCoefAdaos, lnSuma
		
		IF EMPTY(tcTabel)
			lcTabel = this.ct_grid_order1.cnumecursor 
		ELSE 
			lcTabel = ALLTRIM(tcTabel)
		ENDIF 
		
		SELECT (lcTabel)
		SUM ROUND(ABS(cante*pret),gnPc) TO lnSuma
		
		IF lnSuma <> 0
			lnCoefAdaos = (pcobj.totftva-lnSuma)/lnSuma  && coeficientul mediu de adaos
		ELSE 
			lnCoefAdaos = 1
		ENDIF 
		
		SELECT (lcTabel)
		SET FILTER TO 
		REPLACE ALL proc_tvav WITH pcobj.proc_tva, procent WITH ROUND(lnCoefAdaos*100,2)
		CALCULATE cnt() TO lnRecords
		i = 0
		SCAN 
			i = i + 1
			REPLACE pretv WITH ROUND(pret + ROUND(pret*lnCoefAdaos,gnPc),gnPc)		&&	modificare 14.09.2007
			REPLACE tvav WITH ROUND(pretv*(proc_tvav-1),gnPc)
			lnPretv = lnPretv + ROUND(pretv*cante,gnPC)
			lnTvav = lnTvav + ROUND(tvav*cante,gnPC)
			IF i = lnRecords
				IF lnPretv # pcobj.totftva 
					REPLACE pretv WITH pretv + ROUND((pcobj.totftva - lnPretv)/cante,gnPc)
				ENDIF 
				IF lnTvav # pcobj.tottva
					REPLACE tvav WITH tvav + ROUND((pcobj.tottva - lnTvav)/cante,gnPc)
				ENDIF 
			ENDIF 
		ENDSCAN 
		
	ENDPROC

	PROCEDURE calcul_sume
		Parameters tcTabel
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		*!*		Model =-1 : Nota fara contabilizare
		*!*		Model = 1 : Nota simpla cu contabilizare
		*!*		Model = 2 : NIR
		*!*		Model = 3 : BON/FACTURA VANZARE
		*!*		Model = 4 : Retur BON/FACTURA VANZARE
		*!*		Model = 5 : Transfer
		*!*		Model = 6 : Retur Transfer
		*!*		Model = 7 : Diferenta de pret
		
		*!*		Param1 = 1 : En-detail
		*!*		Param1 = 2 : En-gros
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		
		*!* v 2.0.18 - am calculat total cu tva, total tva, total fara tva = diferenta, adaos
		*!* daca gnTipGest = 6 (marfa la pret de vanzare) - valoarea fara tva = valoarea cu tva - valoarea cu tva
		
		Store 0 To lnTotBaza, lnTotTva, lnBazaDiscount, lnBazaAdaos, lnTvaDiscount, lnTvaAdaos
		
		If Pcount() = 0
			tcTabel = Alltrim(This.ct_grid_order1.cnumecursor)
		Endif
		
		*lcCant = [cant] + IIF(INLIST(oset.model, 3, 4),[e],[])  && 3 = bon, bon retur
		lcCant = This.osel_dr.cantitate
		llCalculFact = Iif(oset.param1 = 2, .F., .T.) && daca e En-gros (vanzare) nu mai recalculez Total factura
		
		If This.ct_discount1.Visible = .T.
			lnBazaDiscount = This.ct_discount1.baza_discount
			lnTvaDiscount = This.ct_discount1.tva_discount
		Endif
		
		If oset.adaos
			Do Case
				Case oset.param1 = 1 && factura de vanzare en-detail
					Select (tcTabel)
					Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal
					*!* v 2.0.18 - am calculat total cu tva, total tva, total fara tva = diferenta, adaos
					If gnTipGest <> 6 && calculez valftva si valtva pornind de la pretv in loc de (pretv+tvav)
						Sum Round(&lcCant*pretv - &lcCant*Pret,gnPc) To lnBazaAdaos
						*!*	modificare	31.10.2006
						*!*				SUM ROUND(ROUND((pretv+tvav)/proc_tvav,gnPc)*&lcCant,gnPc) TO lnTotBaza
						*!*				SUM ROUND(ROUND((pretv+tvav)*(proc_tvav-1)/proc_tvav,gnPc)*&lcCant,gnPc) TO lnTotTva
						Sum Round(pretv*&lcCant,gnPc) To lnTotBaza
						Sum Round(Round(pretv*&lcCant,gnPc)*(proc_tvav-1),gnPc) To lnTotTva
						*!*	modificare	31.10.2006	^
					Else 
						Sum Round(Round(pretv+tvav,gnPc)*&lcCant,gnPc) To lnTotctva
						Sum Round(Round((pretv+tvav)*&lcCant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) To lnTotTva
						lnTotBaza = lnTotctva - lnTotTva
						lnBazaAdaos = lnTotBaza - thisform.nTotal 
					EndIf 	
					*!* v 2.0.18 ^
		
					*!*	modificare	v 2.0.6
					If oset.id_set = 75 && Transfer catre gestiune la pret de vanzare
						*!* v 2.0.18 - am calculat total cu tva, total tva, total fara tva = diferenta, adaos
						If gnTipGest <> 6 && calculez valftva si valtva pornind de la pretv in loc de (pretv+tvav)
							Sum Round(tvav*&lcCant,gnPc) To lnTotTvav
						Else 
							Sum Round(Round(pretv*&lcCant,gnPc)*(proc_tvav-1),gnPc) To lnTotTvav				
						EndIf 	
						Thisform.tx_totalctva.Value = lnTotTvav + lnTotBaza
					Endif
					*!*	modificare	v 2.0.6	^
		
				Case oset.param1 = 2 && factura de vanzare en-gros
					This.ct_factura1.totctva = pcobj.totctva
					This.ct_factura1.totftva = pcobj.totftva
					This.ct_factura1.tva = pcobj.tottva
		
					Select (tcTabel)
					Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal
					lnTotBaza = This.ntotal
					lnBazaAdaos = This.ct_factura1.totftva - Thisform.ntotal
					This.ct_adaos1.baza_adaos = lnBazaAdaos
				Otherwise
					Select (tcTabel)
					Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal
					lnTotBaza = This.ntotal
					Sum Round(Round(&lcCant*Pret,gnPc) * (proc_tva-1),gnPc) To lnTotTva
					*!* v 2.0.18 - am calculat total cu tva, total tva, total fara tva = diferenta, adaos	
					If gnTipGest <> 6
						Sum Round(&lcCant*pretv - &lcCant*Pret,gnPc) To lnBazaAdaos
					Else 
						Sum Round(Round(pretv+tvav,gnPc)*&lcCant,gnPc) To lnTotctvaOther
						Sum Round(Round((pretv+tvav)*&lcCant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) To lnTotTvaOther
						lnTotfTvaOhter = m.lnTotctvaOther - m.lnTotTvaOther
						lnBazaAdaos = m.lnTotfTvaOhter - m.lnTotBaza
					EndIf 	
					*!* v 2.0.18 - am calculat total cu tva, total tva, total fara tva = diferenta, adaos
			Endcase
			Select (tcTabel)
			Sum procent To lnProcent
			Calculate Cnt() To lnNrRecord
			lnProcent = lnProcent/lnNrRecord
		
			This.ct_adaos1.baza_adaos = lnBazaAdaos
			This.ct_adaos1.proc_adaos = lnProcent
		Else
			Select (tcTabel)
			Sum Round(&lcCant*Pret,gnPc) To Thisform.ntotal
			lnTotBaza = Thisform.ntotal
		
			Sum Round(Round(&lcCant*Pret,gnPc) * (proc_tva-1),gnPc) To lnTotTva
		
		Endif
		
		
		If oset.factura And llCalculFact
			*!*	modificare facturare in valuta 21.09.2007
			If oset.cursval
				Select (tcTabel)
				*!* v 2.0.18 - am calculat total cu tva, total tva, total fara tva = diferenta, adaos
				If gnTipGest <> 6 && calculez valftva si valtva pornind de la pretv in loc de (pretv+tvav)		
					Sum Round(&lcCant*pretvval,gnPc),Round(Round(&lcCant*pretvval,gnPc)*(proc_tvav-1),gnPc) To lnTotalFTvaVal,lnTotalTvaVal
				Else
					Sum Round(Round(pretvval*proc_tvav,gnPVal)*&lcCant,gnPVal) to lnTotalCTvaVal
					Sum Round(Round(Round(pretvval*proc_tvav,gnPVal)*&lcCant,gnPVal)*(proc_tvav-1),gnPVal) To lnTotalTvaVal
					lnTotalFTvaVal = m.lnTotalCTvaVal - m.lnTotalTvaVal
				EndIf 	
				*!* v 2.0.18 ^
				With Thisform.ct_factura2
					.totftva = lnTotalFTvaVal
					.tva = lnTotalTvaVal
					.totctva = lnTotalFTvaVal + lnTotalTvaVal
					.Refresh()
				Endwith
				lnTotBaza = Round(lnTotalFTvaVal * poAct.Curs,gnPc)
				lnTotTva = Round(lnTotalTvaVal * poAct.Curs,gnPc)
			Endif
			*!*	modificare facturare in valuta 21.09.2007	^
			With This.ct_factura1
				If oset.model = 2 && NIR
					lnBazaAdaos = 0
					lnTvaAdaos = 0
				Endif
				.totftva = lnTotBaza - lnBazaDiscount
				.tva = lnTotTva - lnTvaDiscount
				.totctva = .totftva + .tva
			Endwith
		Endif
		
		*!*	modificare	v 2.0.6
		Do Case
			Case INLIST(oset.id_set , 216,257) && Intrare din transfer de la gest. valorica la pret de vanz.
				Select (tcTabel)
				*!* v 2.0.18 - am calculat total cu tva, total tva, total fara tva = diferenta, adaos
				If gnTipGest <> 6 && calculez valftva si valtva pornind de la pretv in loc de (pretv+tvav)
					Sum Round(pretv*cant,gnPc) To lnTotBaza216
					Sum Round(tvav*cant,gnPc) To lnTotTvav
				Else 
					Sum Round(Round(pretv+tvav,gnPc)*&lcCant,gnPc) To lnTotctva216
					Sum Round(Round((pretv+tvav)*&lcCant,gnPc)*(proc_tvav-1)/proc_tvav,gnPc) To lnTotTvav
					lnTotBaza216 = lnTotctva216 - lnTotTvav
				EndIf 	
				*!* v 2.0.18 ^					
				Thisform.tx_totalctva.Value = lnTotTvav + lnTotBaza216
				*!*	modificare	v 2.0.8
				*!* modificare v 2.0.13
				*!* modificare v 2.0.15 - protocol
			Case Inlist(oset.id_set, 230, 232, 233,261) && protocol
				Select (tcTabel)
				Sum Round((pretv+tvav)*cante,gnPc) To lnTotal230
				Thisform.tx_totalctva.Value = lnTotal230
				*!* modificare v 2.0.15 ^
				*!* modificare v 2.0.13 ^
				*!*	modificare	v 2.0.8	^
		Endcase
		*!*	modificare	v 2.0.6	^
		
		This.txNir.Refresh
		This.ct_factura1.Refresh
		This.ct_factura2.Refresh
		This.ct_adaos1.Refresh
		
	ENDPROC

	PROCEDURE caut_gestiune
		PARAMETERS tnFel
		
		IF EMPTY(tnFel)
			tnFel = 0
		ENDIF 
		
		IF tnFel = 1 && pret vanzare
			lcCond = [nr_pag = 6]
		ELSE 
			lcCond = [nr_pag in (2,3,4,5)]
		ENDIF 
		
		pcselect = [select * from vnom_GESTIUNI]
		pcFiltruOrig = [inactiv = 0 and ] + lcCond
		pcfiltru = [1=2]
		pcschema = []
		pcorder = [NUME_gestiune]
		pccoloane = [nume_gestiune,cgest]
		pcTitlu = [Nume Gestiune Destinatie] 
		pcTitluColoane = [Gestiune,Indicativ]
		locauta = cauta_alfa(pcselect,pcfiltru,pcschema,pcorder,pccoloane,pcTitlu,pcTitluColoane,'',.F.,pcFiltruOrig)		&& 11.07.2007
			
		RETURN locauta
	ENDPROC

	PROCEDURE compensare
		IF USED('xcont')
			SELECT xcont
			LOCATE FOR Pozitie # Fel_Cont AND Cu_Inregistrari = 1
			IF FOUND()
				pcContul = ALLTRIM(cont_part)
				pnIdPart = idPart
				pcNume = numepart
				pnFelCont = Fel_Cont
				pcDenumire = ALLTRIM(explic_cont)
		
				pcCond = [ an = ?gnAn and luna = ?gnluna]
		
				llval = .F. && Deocamdata e doar in lei
				IF llval
					pccond= pccond + [ and ABS(i.precvaldeb + i.valdebit - i.precvalcred - i.valcredit)>0 and i.id_valuta = ] + ALLTRIM(STR(&lcObj..id_valuta))
				ELSE
					pccond= pccond + [ and (i.precvaldeb + i.valdebit - i.precvalcred - i.valcredit = 0) ]
				ENDIF
		
		
		
				pcselect = ['select i.* FROM ] + gcs + [.Vireg_parteneri i where 2=2 ']
				pcfiltru = [ i.id_part = ?pnIdPart AND ABS(i.precdeb + i.debit - i.preccred - i.credit)<>0 AND i.cont = ?pcContul and ] + pcCond
				pcschema = ['']
				pcorder = ['']
		
				PRIVATE podateintrod
				STORE '' TO podateintrod
		
				gencursor('podateintrod','crs_actcv',pcselect,pcfiltru,[''],'')
		
				lcFis = 'actcv' + ALLTRIM(pcContul)
		
				IF USED(lcFis)
					USE IN &lcFis
				ENDIF
		
				IF pnFelCont = 0
					lcsel = [SELECT *, ACONT AS ASCC, nume_val as numeval, curs as cursschimb, precdeb + debit as totctva, preccred+credit as achitat, ] +;
						[precvaldeb + valdebit AS sumaval, precVALcred+VALcredit as achitatval, ] +;
						[.f. as ales, 00000000000000.0000 as sumaachi, 000000000000.0000 as sumaachi2, 00000000000000.0000 as achilei, 00000000000000.0000 as difplus, 00000000000000.0000 as difminus, 000000.0000 as cursval, 000000.0000 as cursdif ] +;
						[FROM crs_actcv INTO CURSOR ] + lcFis + [ READWRITE ]
				ELSE
					lcsel = [SELECT *, ACONT AS ASCD, nume_val as numeval, curs as cursschimb, preccred + credit as totctva, precdeb+debit as achitat, ] + ;
						[precvalcred + valcredit as sumaval, precVALdeb+VALdebit as achitatval, ] + ;
						[.f. as ales, 00000000000000.0000 as sumaachi, 00000000000000.0000 as sumaachi2, 00000000000000.0000 as achilei, 00000000000000.0000 as difplus, 00000000000000.0000 as difminus, 000000.0000 as cursval, 000000.0000 as cursdif ] + ;
						[FROM crs_actcv INTO CURSOR ] + lcFis + [ READWRITE ]
				ENDIF
				&lcsel
		
				SELECT (lcFis)
		
				OPLATA=CREATEOBJECT('ocompensari')
				*		oplata.txtNume.value =lcNume
				OPLATA.titlufrumos1.CAPTION = pcDenumire + [: ] + pcNume
				OPLATA.pcFis = lcFis
				OPLATA.SUMA = THIS.ct_factura1.totctva
				OPLATA.pnFelCont = pnFelCont
				OPLATA.SHOW(1)
		
				*!*			SELECT (lcfis)
				*!*			CALCULATE cnt() FOR ales TO LnBife
				*!*			IF LnBife=1
				*!*				LOCATE FOR ALES
				*!*				&M=nract
				*!*			ELSE
				*!*				&M=0
				*!*			ENDIF
			ENDIF
		ENDIF 
	ENDPROC

	PROCEDURE do_adauga
		PRIVATE pnpretvtva
		pnpretvtva = 0
		lcNomArt = this.ct_grid_search1.cnumecursor 
		SELECT (lcNomArt)
		SCATTER NAME lorec BLANK MEMO 	
		
		*!* 18.050.2007
		*!* marius.mutu
		*!* articolul nou sa fie initializat ca gestionabil (orice program fara ROAPRETURI)
		IF TYPE('gcNumeProgram') = 'C' AND gcNumeProgram <> 'ROAPRETURI'
			loRec.in_stoc = 1		
		ELSE 
			loRec.in_crm = 1			
		ENDIF 
		*!* 18.050.2007 ^
		
		PRIVATE poCote_tva
		STORE '' TO poCote_tva	
		
		DO Adauga_Modifica_Inregistrare WITH [catalog_articole],lorec,,[INSERT]
		this.ct_grid_search1.actualizeaza_grid
	ENDPROC

	PROCEDURE do_modifica
		lcNomArt = this.ct_grid_search1.cnumecursor 
		SELECT (lcNomArt)
		SCATTER NAME lorec 	
		
		PRIVATE poCote_tva
		STORE '' TO poCote_tva
			
		lnId = lorec.id_articol	
		DO Adauga_Modifica_Inregistrare WITH [catalog_articole],lorec,lnId,[UPDATE]
		this.ct_grid_search1.actualizeaza_grid
	ENDPROC

	PROCEDURE do_sterge
		LOCAL lnRecno, lcSelRul
		lcSelRul = this.ct_grid_order1.cnumecursor 
		
		SELECT (lcSelRul)
		*SCATTER NAME osterg
		lnRecno = RECNO()
		DELETE 
		
		*!* MODIFICAT 11.04.2006
		*!* MARIUS.MUTU - AM PUS RECNO('RUL_TEMP') IN CURSORUL DE TRANSFER - LA STERGERE SA POT STERGE SI LINIA CORESPONDENTA DIN CRSTRANSFER	
		IF INLIST(oset.model,5,6,7) AND USED('crsTransfer')	
			SELECT crsTransfer
			GOTO lnRecno
			DELETE 
			this.ct_grid_order1.cb_tx_gestin.SetFocus()
		ENDIF 
		
		this.ct_grid_order1.actualizeaza_grid 
		this.calcul_sume
		
		
	ENDPROC

	PROCEDURE do_termin
		If This.inainte_de_do_termin()
			lcSelRul = This.ct_grid_order1.cnumecursor
			lcSelSt = This.ct_grid_search1.cnumecursor
			gnButon = 1
			pnButon = 1
			Buton = 1
			pnIesire = 1
		*this.Hide
		
			If Type('pnTipCasaMarcat') = 'U'
				pnTipCasaMarcat = 1
			Endif
			If Type('glListareBonFiscal')<>'U' And glListareBonFiscal And pnTipCasaMarcat#1
				lcStringmp500 = ''
				Thisform.bon_fiscal()
				If gnButon<>1
					Return
				Endif
			Endif
		
			Select actactan
			If !Inlist(poact.id_set, 26001) && PV de productie
				This.AlwaysOnTop = .F.
				Do Form verificare With .T.,.T.,3  && cu buton de precedent
				This.AlwaysOnTop = .T.
			Endif
			Do Case
			Case gnButon = 3
		*onirbon.visible = .t.
				Do nrord With lcSelRul
			Otherwise
				This.Release
			Endcase
		Endif
	ENDPROC

	PROCEDURE do_verifica_sume
		tcTabel = Alltrim(This.ct_grid_order1.cnumecursor)
		Select (tcTabel)
		Replace id_valuta_vanz With poAct.id_valuta_vanz All
		Calculate Sum(Round(pretvval*cante,gnPc)),Sum(Round(pretv*cante,gnPc)) To lnTotalVal,lnTotalLei
		lnTotalVal = Round(lnTotalVal*poAct.Curs,gnPc)
		If lnTotalVal <> lnTotalLei
			lnDiferenta = lnTotalVal - lnTotalLei
			lnSemn = Sign(lnDiferenta)
		*!*		lnDiferenta = Abs(lnDiferenta)
			lnDiferenta = lnDiferenta
			lnDiferentaPretU = Exp((-1)*gnPc*Log(10))
			lnModificari = 1
		
			Do While lnModificari <> 0
				lnModificari = 0
				Select (tcTabel)
				Scan
					lnDiferentaPret = Round(lnDiferentaPretU*cante,gnPc)
					lnSemnPret = Sign(lnDiferentaPret)
					If Abs(lnDiferentaPret) <= Abs(lnDiferenta)
						lnDiferenta = lnDiferenta - lnSemn * lnDiferentaPret
						Replace pretv With pretv + lnSemn * lnSemnPret * lnDiferentaPretU
						lnModificari = lnModificari + 1
					Endif
				Endscan
			Enddo
		Endif
		
	ENDPROC

	PROCEDURE inainte_de_do_termin
		Local lcSelRul, lcSelRulGr,lcContTr, lcAcontTr, lcRul, lcSql, lcCursor, lnSucces, lcCant, lnIdGestiuneTr
		
		Store '' To lcContTr, lcAcontTr
		lnIdGestiuneTr = 0
		lcSelRulGr = This.ct_grid_order1.cnumecursor
		Local lnRecno
		lnRecno = 0
		pnBazaV341       	= 0
		pnBazaV346       	= 0
		pnBazaVProd       	= 0
		pnBazaVAmb 			= 0
		pnBazaVal341       	= 0
		pnBazaVal346       	= 0
		pnBazaValProd       = 0
		pnBazaValAmb 		= 0
		 
		*!* 15.03.2007
		Local llY
		llY = .F.
		*!* 15.03.2007 ^
		*!*	modificare facturare in valuta 24.09.2007
		If oset.cursval
			Thisform.do_verifica_sume()
		Endif
		*!*	modificare facturare in valuta 24.09.2007	^
		
		Thisform.compensare && PT 542 ; se completeaza actactanul in adunadate
		
		*** completez tabela ACTACTAN
		If Type('oitem') = 'O'
			If Pemstatus(oitem,'adunadate',5)
				oitem.adunadate()
			Endif
		Endif
		***
		
		If Used('rul_temp')
			Use In rul_temp
		Endif
		&& completez RUL_TEMP
		lcRul = Alltrim(This.osel_dr.cfrom)
		lcSql = [select v.*,0 as pretvval,0 as curs,0 as id_valuta_vanz,0 as id_jtva_coloana, v.id_gestiune as id_gestin, v.nume_gestiune as gestin, v.id_gestiune as id_gestout, v.nume_gestiune as gestout, 0 as nuInConturiX]
		
		&& VRUL_OBINV NU ARE CODMATF, LOT, ADATA_EXPIRARE SI NU SE MAI SALVEAZA LOT, ADATA_EXPIRARE IN RUL
		IF 'obinv'$LOWER(lcRul) 
			lcSql = lcSql + [,rpad(' ',50,' ') as codmatf, rpad(' ',50,' ') as lot, to_date('') as adata_expirare]
		ENDIF 
		lcSql = lcSql + [ from ] + lcRul + [ where 1=2]
		lcCursor = [rul_temp]
		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		If lnSucces < 0
			Return .F.
		Endif
		
		
		Select rul_temp
		Append From Dbf(lcSelRulGr)
		lcSelRul = 'rul_temp'
		
		If oset.productie
			Do Case
			Case Alltrim(Upper(oset.formproduc))='FRM_ALEGE_PROD_CANT'
				Thisform.intrare_produs()
			Case INLIST(Alltrim(Upper(oset.formproduc)),'FRM_ALEGE_SECTIE_COMANDA','FRM_ALEGE_SECTIE')
				Select actactan
		*!*		modificare 03.09.2007
		*!*			Replace id_sectie With pnId_sectie, sectie With pcSectie For Inlist(nr_nota,1,2,5)
				Replace id_sectie With 0, sectie With '' For Inlist(nr_nota,4)
			Endcase
		Endif
		
		*!* 15.03.2007
		*!* pentru intrare dintr-o gestiune tinuta doar valoric - trebuie contul
		*!* daca exista Y (trebuie sa aleaga contul de transfer)
		Select xscd As SCD, xscc As scc From XNOTE Where id_set = oset.id_set ;
			AND (Inlist(Upper(Alltrim(xscd)),'Y') Or Inlist(Upper(Alltrim(xscc)),'Y'));
			INTO Cursor crsY
		If _Tally > 0 Or Inlist(oset.model, 5, 6, 7)
			llY = .T.
		Endif
		Use In crsY
		*!* 15.03.2007 ^
		
		If Inlist(oset.model, 5, 6, 7) && TRANSFER, RETUR TRANSFER
		
			Select (lcSelRul)
			lnRecno = Recno()
			If oset.id_set = 211 && TRANSFER GESTIUNE OB INV IN FOLOSINTA PE PERSOANA CATRE O MAGAZIE OB INV IN FOLOSINTA
				Replace id_responsabil With 0, nresp With ''
			Endif
		
			If Used('crsTransfer')
				Append From Dbf('crsTransfer')
		
				If oset.id_set = 210 && TRANSFER MAGAZIE OB INV IN FOLOSINTA CATRE O GESTIUNE OB INV IN FOLOSINTA PE PERSOANA
					Replace id_responsabil With 0, nresp With '' For Recno() > lnRecno
				Endif
		
		*!*	modificare 22.05.2007
		***	se modifica pretul de ach. pentru intrari
				If oset.id_set = 218
					Replace Pret With pretv For cant <> 0
				Endif
		*!*	modificare 22.05.2007 ^
			Endif
		
			If !Inlist(oset.id_set,89, 210, 211, 212)  && (FARA TRANSFER INTRE PERSOANE)
				If Inlist(oset.id_seldr,11,16,18) && achizitie
					poGestTr = This.caut_gestiune()
				Endif
				If oset.id_seldr = 12 && vanzare
					poGestTr = This.caut_gestiune(1)
				Endif
				If Empty(poGestTr.Id_gestiune)  && renunt
					Return .F.
				Endif
		
		&& Dc poGestTr.Id_gestiune nu e empty aleg contul de transfer si analiticul
		
				loCont = This.aleg_cont_transfer(poGestTr.Id_gestiune)
		
				If Empty(loCont.Cont)	&& renunt
					Return .F.
				Endif
		
				Select (lcSelRul)
				Replace All id_gestin With poGestTr.Id_gestiune, gestin With poGestTr.nume_gestiune   &&FOR cant <> 0
				Do Case
				Case Inlist(oset.model,5,7) && transfer
					Replace All Id_gestiune With poGestTr.Id_gestiune, nume_gestiune With poGestTr.nume_gestiune For cant <> 0
				Case oset.model = 6 && retur
					Replace All Id_gestiune With poGestTr.Id_gestiune, nume_gestiune With poGestTr.nume_gestiune For cante <> 0
				Endcase
		
				lcContTr = loCont.Cont
				lcAcontTr = loCont.acont
		
				Select actactan
				Replace All SCD With lcContTr, ascd With lcAcontTr, id_gestin With poGestTr.Id_gestiune, gestin With poGestTr.nume_gestiune For Upper(Alltrim(SCD)) = 'Y'
				Select (lcSelRul)
				If oset.model = 6
					lcCant = Thisform.osel_dr.cantitate
				Else
					lcCant = [cant]
				Endif
				Replace All Cont With lcContTr, acont With lcAcontTr For &lcCant <> 0
		*!*			REPLACE ALL id_gestiunec WITH id_gestout FOR cant <> 0
		*!*			REPLACE ALL id_gestiunec WITH id_gestin FOR cante <> 0
		*!*			REPLACE ALL nuInConturiX WITH 1 FOR cant <> 0
			Endif
			Select (lcSelRul)
			Replace All id_gestiunec With id_gestout For cant <> 0
			Replace All id_gestiunec With id_gestin For cante <> 0
			Replace All nuInConturiX With 1 For cant <> 0
		Endif
		
		Select (lcSelRul)
		
		If oset.param1 = 2 And oset.factura  &&  factura en-gros
			This.calcul_pret_vanzare(lcSelRul)
		*!*	modificare 31.10.2006
			pnTotalFactura = This.ct_factura1.totctva
			pnBazaFactura = This.ct_factura1.totftva
			pnTvaFactura = This.ct_factura1.tva
		
			Select rul_temp
			Calculate Sum(Round(Round(pretv,gnPc)*cante,gnPc)),;
				SUM(Round(Round(Round(pretv,gnPc)*cante,gnPc)*(proc_tvav-1),gnPc)) ;
				TO lnBazaFactura,lnTvaFactura
		
			Do Case
			Case lnBazaFactura <> pnBazaFactura And lnTvaFactura <> pnTvaFactura
				lcMesaj = [Diferenta intre sumele introduse si cele rezultate din calcul:] + CRLF + ;
					SPACE(23) + [Baza] + Space(18) + [TVA] + CRLF + ;
					[Introduse:] + Space(5) + Str(pnBazaFactura,20,gnPc) + [ ] + Str(pnTvaFactura,20,gnPc) + ;
					CRLF +;
					[Calculate:] + Space(5) + Str(lnBazaFactura,20,gnPc) + [ ] + Str(lnTvaFactura,20,gnPc) + ;
					CRLF + CRLF + ;
					[Doriti sa continuati?]
			Case lnBazaFactura <> pnBazaFactura
				lcMesaj = [Diferenta intre sumele introduse si cele rezultate din calcul:] + CRLF + ;
					SPACE(23) + [Baza] + CRLF + ;
					[Introduse:] + Space(5) + Str(pnBazaFactura,20,gnPc) + CRLF+;
					[Calculate:] + Space(5) + Str(lnBazaFactura,20,gnPc) + CRLF + CRLF + ;
					[Doriti sa continuati?]
			Case lnTvaFactura <> pnTvaFactura
				lcMesaj = [Diferenta intre sumele introduse si cele rezultate din calcul:] + CRLF + ;
					SPACE(24) + [TVA] + CRLF + ;
					[Introduse:] + Space(5) + Str(pnTvaFactura,20,gnPc) + CRLF +;
					[Calculate:] + Space(5) + Str(lnTvaFactura,20,gnPc) + CRLF + CRLF + ;
					[Doriti sa continuati?]
			Otherwise
				lcMesaj = []
			Endcase
		
			If !Empty(lcMesaj)
				If aMessagebox(lcMesaj,4+32+256,"Confirmare")==7
					Return .F.
				Else
					pnBazaFactura = lnBazaFactura
					pnTvaFactura = lnTvaFactura
					pnTotalFactura = lnBazaFactura + lnTvaFactura
				Endif
			Endif
		Else
			pnTotalFactura = This.ct_factura1.totctva
			pnBazaFactura = This.ct_factura1.totftva
			pnTvaFactura = This.ct_factura1.tva
		*!*	modificare 31.10.2006	^
		Endif
		
		pnDiscount = This.ct_discount1.baza_discount
		pnTVADiscount = -This.ct_discount1.tva_discount
		pnProcDiscount = This.ct_discount1.pnTva
		pnIdJtvaDiscount = This.ct_discount1.nid_jtva_coloana
		pnIdTvaDiscount = This.ct_discount1.nid_tva
		*!*	pnTotalFactura = THIS.ct_factura1.totctva
		*!*	pnBazaFactura = THIS.ct_factura1.totftva
		*!*	pnTvaFactura = THIS.ct_factura1.tva
		
		pnBazaNir  = [pret*cant]
		pnBazaBon  = [pret*cante]
		pnTotalBon = This.ntotal
		pnTotalNir = This.ntotal
		*pnTvaNir = [tva*cant]
		pnTvaNir = [pret*cant]
		*!*	modificari	31.10.2006
		*!*	*pnBazaVanz = [pretv*cante]
		*!*	pnBazaVanz = [ROUND(ROUND((pretv+tvav)/proc_tvav,gnPc)*cante,gnPc)]
		*!*	*pnTvaVanzIn = [tvav*cant]
		*!*	*pnTvaVanzIn = [pretv*cant]
		*!*	pnTvaVanzIn = [ROUND(ROUND((pretv+tvav)*(proc_tvav-1)/proc_tvav,gnPc)*cant,gnPc)]
		*!*	*pnTvaVanzOut = [tvav*cante]
		*!*	*pnTvaVanzOut = [pretv*cante]
		*!*	pnTvaVanzOut = [ROUND(ROUND((pretv+tvav)*(proc_tvav-1)/proc_tvav,gnPc)*cante,gnPc)]
		pnBazaVanz = [ROUND(pretv*cante,gnPc)]
		pnBazaVal = [ROUND(pretvval*cante,gnPVal)]
		pnBazaValVanz = [ROUND(ROUND(pretvval*curs,gnPC)*cante,gnPC)]
		*** 04.07.2007 - modificat in calcul si raport rap_nirtransfer_vanz valoare tva
		*pnTvaVanzIn = [ROUND(ROUND(pretv*cant,gnPc)*(proc_tvav-1),gnPc)]
		*!*	modificare 17.09.2007
		pnTvaVanzIn = [ROUND(tvav*cant,gnPc)]
		*!*	pnTvaVanzIn = [ROUND(ROUND(pretv*cant,gnPc)*(proc_tvav-1),gnPc)]
		*!*	modificare 17.09.2007	^
		
		*pnTvaVanzOut = [ROUND(ROUND(pretv*cante,gnPc)*(proc_tvav-1),gnPc)]
		*!*	modificare 17.09.2007
		*!*	pnTvaVanzOut = [ROUND(tvav*cante,gnPc)]
		pnTvaVanzOut = [ROUND(ROUND(pretv*cante,gnPc)*(proc_tvav-1),gnPc)]
		pnTvaVanzOut2 = [Round(tvav*cante,gnPc)]						&&	modificare	v 2.0.8
		pnTvaVal = [ROUND(ROUND(pretvval*cante,gnPVal)*(proc_tvav-1),gnPVal)]
		pnTvaValVanz = [ROUND(ROUND(ROUND(pretvval*curs,gnPC)*cante,gnPC)*(proc_tvav-1),gnPC)]
		*!*	modificare 17.09.2007	^
		***
		
		If oset.id_set = 104 And gnImputare = 1
			pnBazaVanz = [ROUND(pret_imputare*cante,gnPc)]
			pnTvaVanzOut = [ROUND(ROUND(pret_imputare*cante,gnPc)*(proc_tvav-1),gnPc)]
		Endif
		*!*	modificari	31.10.2006	^
		pnAdaosTotal = This.ct_adaos1.baza_adaos
		pnBazaPlusAdaos = pnTotalBon + pnAdaosTotal
		
		lcCant = Lower(Alltrim(This.osel_dr.cantitate))
		If Inlist(oset.model, 5, 6, 7) && transfer
			lcCant = 'cante'
		Endif
		pnAdaos = [pretv*] + lcCant + [-pret*] + lcCant
		
		Select * From XNOTE Where id_set = oset.id_set Into Cursor crsNota
		
		lcField = ''
		Select xact
		Go Top
		
		For i = 1 To Fcount()
			If Upper(Alltrim(Evaluate(Field(i)))) = 'SUMA'
				lcField = Field(i)
				Exit
			Endif
		Endfor
		
		If Empty(lcField)
			Return .T.
		Endif
		
		Select Distinct xscd As SCD, xscc As scc, Padr(&lcField,100,' ') As eticheta,x34 From crsNota ;
			WHERE Inlist(Upper(Alltrim(xscd)),'X') Or Inlist(Upper(Alltrim(xscc)),'X');
			INTO Cursor crsIcsi
		If _Tally > 0
			Select crsIcsi
			Scan
				lcEticheta = Lower(Alltrim(eticheta))
				If Empty(lcEticheta)
					aMessagebox('NECONFIGURAT xnote.dbf !',48,'Atentie!')
					Loop
				Endif
				lcSCD = Upper(Alltrim(SCD))
				lcSCC = Upper(Alltrim(scc))
				lcIDJtva = Upper(Alltrim(x34))
				If Inlist(oset.model, 5, 6, 7) && TRANSFER, RETUR TRANSFER
					If lcSCD = 'Y'
						lcSCD = lcContTr
					Endif
					If lcSCC = 'Y'
						lcSCC = lcContTr
					Endif
				Endif
		
		&& despart sumele pe gestiuni si sectii - pt formarea corecta a analiticelor
				If 'pntvavanz' $ lcEticheta Or 'pnadaos' $ lcEticheta
		
		*!*				IF 'pnadaos'$lcEticheta
					If Type('&lcEticheta') <> 'N'
						lcEticheta =  &lcEticheta
					Endif
					lcSuma = [SUM(ROUND(&lcEticheta,gnPc))]
		*!*				ELSE
		*!*					lcEticheta =  &lcEticheta
		*!*					lcSuma = [SUM(ROUND(ROUND(&lcEticheta,gnPc)*(proc_tvav-1),gnPc))]
		*!*				ENDIF
		
					lcSelect = [SELECT CONT,ACONT,id_gestiune,id_sectie,sectie,] + ;
						IIF(Type(lcSelRul+'.id_jtva_coloana')#'U',[id_jtva_coloana],[NULL]) + [ as id_jtva_coloana,] + ;
						IIF(Type(lcSelRul+'.proc_tvav')#'U',[proc_tvav],[0000]) + [ as proc_tva,] +;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[id_gestin],[000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ AS suma ] + ;
						[FROM ] + lcSelRul + [ where nuInConturiX = 0 into cursor crsConturiX ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11]
					&lcSelect
				Else
					If Type('&lcEticheta') <> 'N'
						lcEticheta =  &lcEticheta
					Endif
		
					lcSuma = [SUM(ROUND(&lcEticheta,gnPc))]
		*!*				lcSuma = [SUM(ROUND(]+ALLTRIM(STR(lcEticheta,20,6))+[,gnPc))]
					lcSelect = [SELECT CONT,ACONT,id_gestiune,id_sectie,sectie,] + ;
						IIF(Type(lcSelRul+'.id_jtva_coloana')#'U',[id_jtva_coloana],[NULL]) + [ as id_jtva_coloana,] + ;
						IIF(Type(lcSelRul+'.proc_tva')#'U',[proc_tva],[0000]) + [ as proc_tva,] +;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[id_gestin],[000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ AS suma ] + ;
						[FROM ] + lcSelRul + [ where nuInConturiX = 0 into cursor crsConturiX ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11]
					&lcSelect
				Endif
		
				Select crsConturiX
		
				Scan For suma*0 = 0 && sa evit cazurile in care suma este ******
					Scatter Name loCX
		
					Select actactan
					Locate For Upper(Alltrim(SCD)) = lcSCD And Upper(Alltrim(scc)) = lcSCC
					If Found()
		
						Scatter Name loActactan
						With loActactan
							If Upper(Alltrim(.SCD)) = 'X'
								.SCD = loCX.Cont
								.ascd = Nvl(loCX.acont,'')
								.suma = loCX.suma
								If !Empty(lcIDJtva) && AND !INLIST(oset.model,5,6)
									.id_jtva_coloana = loCX.id_jtva_coloana
									.proc_tva = loCX.proc_tva
								Else
									.id_jtva_coloana = Null
									.proc_tva = 0
								Endif
								.id_gestin = loCX.id_gestin
								.gestin = loCX.gestin
								.id_gestout = loCX.id_gestout
								.gestout = loCX.gestout
								.id_sectie = loCX.id_sectie
								.sectie = loCX.sectie
							Endif
							If Upper(Alltrim(.scc)) = 'X'
								.scc = loCX.Cont
								.ascc = Nvl(loCX.acont,'')
								.suma = loCX.suma
								*!*	modificare 04.10.2007
		*!*								If Left(.scd,1) = '6' And Alltrim(.scd) # '607' And Inlist(oset.model, 3, 4) && BON, RETUR
		*!*									If .scc = '381'
		*!*										.scd = '608'
		*!*									Else
		*!*										.scd = Strtran(.scc, '3', '6', 1, 1)
		*!*									Endif
		*!*								Endif
								If Inlist(oset.model,3,4)
									Select crsconfigcvc
									Locate For Cont = Upper(Alltrim(.scc))
									If Found() AND (EMPTY(.scd) OR INLIST(LEFT(.scd,1), '6','7'))
										.scd = ALLTRIM(cont_chelt)
									Else
										If Left(.scd,1) = '6' And Alltrim(.scd) # '607'
											If .scc = '381'
												.scd = '608'
											Else
												.scd = Strtran(.scc, '3', '6', 1, 1)
											Endif
										Endif
									Endif
									SELECT actactan
								Endif
								*!*	modificare 04.10.2007	^
								If !Empty(lcIDJtva) && AND !INLIST(oset.model,5,6)
									.id_jtva_coloana = loCX.id_jtva_coloana
									.proc_tva = loCX.proc_tva
								Else
									.id_jtva_coloana = Null
									.proc_tva = 0
								Endif
								.id_gestin = loCX.id_gestin
								.gestin = loCX.gestin
								.id_gestout = loCX.id_gestout
								.gestout = loCX.gestout
								.id_sectie = loCX.id_sectie
								.sectie = loCX.sectie
							Endif
						Endwith
						Append Blank
						Gather Name loActactan
					Endif && IF FOUND()
		
					Select crsConturiX
				Endscan
				Select crsIcsi
			Endscan
		
			Delete From actactan Where Inlist(Upper(Alltrim(SCD)),'X') Or Inlist(Upper(Alltrim(scc)),'X')
		Endif
		*!* 15.03.2007 ^
		*!* inlocuiesc Y - la notele care nu sunt transfer sau retur transfer (intrare dintr-o gestiune tinuta valoric - trebuie contul)
		If !Inlist(oset.model, 5, 6, 7) And llY
			Select rul_temp
			Go Top
			lnIdGestiuneTr = Id_gestiune
			If !Empty(lnIdGestiuneTr)
		
				loCont = This.aleg_cont_transfer(lnIdGestiuneTr)
				lcContTr = loCont.Cont
				lcAcontTr = loCont.acont
				Select actactan
		
				Replace All SCD With lcContTr, ascd With lcAcontTr For Upper(Alltrim(SCD)) = 'Y'
				Replace All scc With lcContTr, ascc With lcAcontTr For Upper(Alltrim(scc)) = 'Y'
		
			Endif
		
		*!* 20.03.2007
		*!* cont de transfer - cont din nomenclator
		*!* in rul aj trebuie sa am pe intrari contul din debit (contul de transfer)
			If oset.model = 2 Or Upper(Alltrim(oset.formgest)) = 'NIR'
				Select rul_temp
				Replace All Cont With lcContTr
			Endif
		Endif
		
		*!* 15.03.2007 ^
		Select crsNota
		Scan For !(Inlist(Upper(Alltrim(xscd)),'X') Or Inlist(Upper(Alltrim(xscc)),'X'))
			Scatter Name loNota
		
			lcVariabila = Lower(Alltrim(loNota.&lcField))
			lcIDJtva = Upper(Alltrim(x34))
			If Inlist(oset.model, 5, 6, 7) Or llY && TRANSFER, RETUR TRANSFER
				If loNota.xscd = 'Y'
					loNota.xscd = lcContTr
					loNota.xAscd = lcAcontTr
				Endif
				If loNota.xscc = 'Y'
					loNota.xscc = lcContTr
					loNota.xAscc = lcAcontTr
				Endif
			Endif
		
			Do Case
			Case 'pntvanir' $ lcVariabila
				lcVariabila = &lcVariabila
				lcSelect = [SELECT b.id_tva as id_jtva_coloana,a.proc_tva,a.id_sectie,a.id_gestiune,a.sectie,] + ;
					IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
					IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
					IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
					IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
					[SUM(ROUND(ROUND(&lcVariabila,gnPc)*(a.proc_tva-1),gnPc)) as suma ] + ;
					[FROM ] + lcSelRul + [ a LEFT JOIN jtva_coloane b ON a.id_jtva_coloana = b.id_jtva_coloana ] + ;
					[INTO CURSOR crsTva ] + ;
					[GROUP BY 1,2,3,4,5,6,7,8,9]
				&lcSelect
		
				Select crsTva
				i  = 0
				Scan For suma*0 = 0 && sa evit cazurile in care suma este ******
					i = i + 1
					If i = 1
						Select actactan
						Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
						If Found()
							Scatter Name loAct
							Delete
						Else
							Scatter Name loAct Blank
						Endif
					Endif
					Select crsTva
					Scatter Name loTva
					Select actactan
					Append Blank
					Gather Name loAct
					Gather Name loTva
					If Empty(lcIDJtva)
						Replace id_jtva_coloana With Null,proc_tva With 0
					Endif
				Endscan
			Case 'pnbazavanz'$lcVariabila Or 'pntvavanz'$lcVariabila
		*!*				IF 'pnbazavanz'$lcVariabila
				&& 05.09.2007
				&& marius.mutu
				&& linia If 'pnbazavanz'$lcVariabila intra mereu pe else si punea o baza cu id_jtva_coloana de tva
				lcVariabilatemp = lcVariabila
				
				lcVariabila = &lcVariabila
				lcSuma = [sum(ROUND(&lcVariabila,gnPc))]
		*!*				ELSE
		*!*					lcVariabila = &lcVariabila
		*!*					lcSuma = [SUM(ROUND(ROUND(&lcVariabila,gnPc)*(proc_tvav-1),gnPc))]
		*!*				ENDIF
				If 'pnbazavanz'$lcVariabilatemp
					lcSelect = [SELECT a.id_jtva_coloana,a.proc_tvav,a.id_sectie,a.id_gestiune,a.sectie,] + ;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ as suma ] + ;
						[FROM ] + lcSelRul + [ a ] + ;
						[INTO CURSOR crsTva ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9]
				Else
					lcSelect = [SELECT b.id_tva as id_jtva_coloana,a.proc_tvav,a.id_sectie,a.id_gestiune,a.sectie,] + ;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
						lcSuma + [ as suma ] + ;
						[FROM ] + lcSelRul + [ a LEFT JOIN jtva_coloane B ON A.ID_JTVA_COLOANA = B.ID_JTVA_COLOANA ] + ;
						[INTO CURSOR crsTva ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9]
				Endif
				&lcSelect
		
				Select crsTva
				i  = 0
				Scan For suma*0 = 0  && sa evit cazurile in care suma este ******
					i = i + 1
					If i = 1
						Select actactan
						Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
						If Found()
							Scatter Name loAct
							Delete
						Else
							Scatter Name loAct Blank
						Endif
					Endif
					Select crsTva
					Scatter Name loTva
					Select actactan
					Append Blank
					Gather Name loAct
					Gather Name loTva
					Replace proc_tva With loTva.proc_tvav
					If Empty(lcIDJtva)
						Replace id_jtva_coloana With Null
					Endif
				Endscan
		*!*	modificare facturare in valuta 21.09.2007
			Case 'pnbazaval'$lcVariabila Or 'pntvaval'$lcVariabila
				lcVariabilatemp = lcVariabila
				lcVariabila = &lcVariabila
				lcSumaVal = [sum(&lcVariabila)]
				If 'pnbazaval'$lcVariabilatemp
		*!*				lcSuma = [SUM(]+pnBazaValVanz+[)]
					lcSuma = [ROUND(SUM(]+pnBazaVal+[)*a.curs,gnPc)]
					lcSelect = [SELECT a.id_jtva_coloana,a.proc_tvav,a.id_sectie,a.id_gestiune,a.sectie,] + ;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
						[NVL(a.id_valuta_vanz,0) as id_valuta,] + ;
						IIF(TYPE(lcSelRul+'.curs') #'U',[a.curs],[0]) + [ as curs,] + ;
						lcSumaVal + [ as suma_val,] + lcSuma + [ as suma ] + ;
						[FROM ] + lcSelRul + [ a ] + ;
						[INTO CURSOR crsTva ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11]
				Else
		*!*				lcSuma = [SUM(]+pnTvaValVanz+[)]
					lcSuma = [ROUND(SUM(]+pnTvaVal+[)*a.curs,gnPc)]
					lcSelect = [SELECT b.id_tva as id_jtva_coloana,a.proc_tvav,a.id_sectie,a.id_gestiune,a.sectie,] + ;
						IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
						IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
						IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
						IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
						[NVL(a.id_valuta_vanz,0) as id_valuta,] + ;
						IIF(TYPE(lcSelRul+'.curs') #'U',[a.curs],[0]) + [ as curs,] + ;
						lcSumaVal + [ as suma_val,] + lcSuma + [ as suma ] + ;
						[FROM ] + lcSelRul + [ a LEFT JOIN jtva_coloane B ON A.ID_JTVA_COLOANA = B.ID_JTVA_COLOANA ] + ;
						[INTO CURSOR crsTva ] + ;
						[GROUP BY 1,2,3,4,5,6,7,8,9,10,11]
				Endif
				&lcSelect
		
				Select crsTva
				i  = 0
				Scan For suma_val*0 = 0  && sa evit cazurile in care suma este ******
					i = i + 1
					If i = 1
						Select actactan
						Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
						If Found()
							Scatter Name loAct
							Delete
						Else
							Scatter Name loAct Blank
						Endif
					Endif
					Select crsTva
					Scatter Name loTva
					AddProperty(loTva,[nume_val],poAct.nume_val_vanz)
					Select actactan
					Append Blank
					Gather Name loAct
					Gather Name loTva
					Replace proc_tva With loTva.proc_tvav
					If Empty(lcIDJtva)
						Replace id_jtva_coloana With Null
					Endif
				Endscan
		*!*	modificare facturare in valuta 21.09.2007	^
			Case 'pnbazabon'$lcVariabila
				lcSuma = [SUM(ROUND(&lcEticheta,gnPc))]
		*!*			lcSelect = [SELECT CONT,ACONT,id_gestiune,id_sectie,sectie,] + ;
		*!*				IIF(Type(lcSelRul+'.id_jtva_coloana')#'U',[id_jtva_coloana],[NULL]) + [ as id_jtva_coloana,] + ;
		*!*				IIF(Type(lcSelRul+'.proc_tva')#'U',[proc_tva],[0000]) + [ as proc_tva,] +;
		*!*				IIF(Type(lcSelRul+'.id_gestin')#'U',[id_gestin],[000000000]) + [ as id_gestin,] + ;
		*!*				IIF(Type(lcSelRul+'.id_gestout')#'U',[id_gestout],[000000000]) + [ as id_gestout,] + ;
		*!*				IIF(Type(lcSelRul+'.gestin')#'U',[gestin],[SPACE(50)]) + [ as gestin,] + ;
		*!*				IIF(Type(lcSelRul+'.gestout')#'U',[gestout],[SPACE(50)]) + [ as gestout,] + ;
		*!*				lcSuma + [ AS suma ] + ;
		*!*				[FROM ] + lcSelRul + [ where nuInConturiX = 0 into cursor crsTva ] + ;
		*!*				[GROUP BY 1,2,3,4,5,6,7,8,9,10,11]
		
				lcSelect = [SELECT a.id_jtva_coloana,a.proc_tvav,a.id_sectie,a.id_gestiune,a.sectie,] + ;
					IIF(Type(lcSelRul+'.id_gestin')#'U',[a.id_gestin],[0000000000]) + [ as id_gestin,] + ;
					IIF(Type(lcSelRul+'.id_gestout')#'U',[a.id_gestout],[000000000]) + [ as id_gestout,] + ;
					IIF(Type(lcSelRul+'.gestin')#'U',[a.gestin],[SPACE(50)]) + [ as gestin,] + ;
					IIF(Type(lcSelRul+'.gestout')#'U',[a.gestout],[SPACE(50)]) + [ as gestout,] + ;
					lcSuma + [ as suma ] + ;
					[FROM ] + lcSelRul + [ a ] + ;
					[INTO CURSOR crsTva ] + ;
					[GROUP BY 1,2,3,4,5,6,7,8,9]
				&lcSelect
		
				Select crsTva
				i  = 0
				Scan For suma*0 = 0  && sa evit cazurile in care suma este ******
					i = i + 1
					If i = 1
						Select actactan
						Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
						If Found()
							Scatter Name loAct
							Delete
						Else
							Scatter Name loAct Blank
						Endif
					Endif
					Select crsTva
					Scatter Name loTva
					Select actactan
					Append Blank
					Gather Name loAct
					Gather Name loTva
					Replace proc_tva With loTva.proc_tvav
					If Empty(lcIDJtva)
						Replace id_jtva_coloana With Null
					Endif
				Endscan
			Otherwise
				Select actactan
				Locate For SCD = loNota.xscd And scc = loNota.xscc And suma = 0
				If Found()
					If !Empty(lcVariabila)
						Replace suma With &lcVariabila
					Endif
				Endif
				If 'discount' $ lcVariabila
					Replace proc_tva With pnProcDiscount,id_jtva_coloana With &lcIDJtva
				Endif
			Endcase
		Endscan
		
		If Used('crsIcsi')
			Use In crsIcsi
		Endif
		If Used('crsConturiX')
			Use In crsConturiX
		Endif
		If Used('crsNota')
			Use In crsNota
		Endif
		
		*!*	IF USED('rul_temp')
		*!*		USE IN rul_temp
		*!*	ENDIF
		
		*!*	&& completez RUL_TEMP
		*!*	lcRul = ALLTRIM(THIS.osel_dr.cfrom)
		*!*	lcSql = [select * from ] + gcS + [.] + lcRul + [ where 1=2]
		*!*	lcCursor = [rul_temp]
		*!*	lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		*!*	IF lnSucces < 0
		*!*		RETURN .F.
		*!*	ENDIF
		
		*!*	lcCant = LOWER(ALLTRIM(this.osel_dr.cantitate))
		*!*	lcCantTransf = [cant] + iif(lcCant = [cante],[],[e])
		
		*!*	IF INLIST(oset.model, 5, 6) && TRANSFER, RETUR TRANSFER
		
		*!*		SELECT * FROM (lcSelRul) INTO CURSOR crsTransf NOFILTER READWRITE
		*!*		REPLACE ALL &lcCantTransf WITH &lcCant FOR !EMPTY(&lcCant)
		*!*		REPLACE ALL &lcCant WITH 0
		*!*		APPEND FROM DBF(lcSelRul)
		*!*		IF oset.id_set <> 89 && TRANSFER INTRE PERSOANE
		*!*			REPLACE ALL cont WITH lcContTr, acont WITH lcAcontTr FOR &lcCantTransf # 0
		*!*		ELSE
		*!*			SELECT (this.ct_grid_search1.cnumecursor)
		*!*			SCATTER NAME loStg
		*!*			SELECT crsTransf
		*!*			REPLACE ALL id_gestin WITH id_gestout
		*!*			REPLACE ALL id_responsabil WITH loStg.id_responsabil, nresp WITH loStg.nresp FOR cante <> 0
		*!*		ENDIF
		*!*		REPLACE ALL id_gestiune WITH id_gestin,nume_gestiune WITH gestin FOR &lcCantTransf <> 0
		*!*		REPLACE ALL id_gestiune WITH id_gestout, nume_gestiune WITH gestout FOR &lcCant <> 0
		*!*
		*!*		SELECT rul_temp
		*!*		APPEND FROM DBF('crsTransf')
		*!*		IF USED('crsTransf')
		*!*			USE IN crsTransf
		*!*		ENDIF
		*!*
		*!*		lcSel = [SELECT id_gestiune from ] + gcs + [.vnom_gestiuni WHERE nr_pag = 6]
		*!*		lcCursor = 'crsIdVanzare'
		*!*		lnSucces = goExecutor.oExecute(lcSel,lcCursor)
		*!*		IF lnSucces < 0
		*!*			MESSAGEBOX(goExecutor.cEroare,0+16,"Eroare")
		*!*		ENDIF
		*!*
		*!*		IF lnSucces > 0
		*!*			UPDATE rul_temp SET pretv = 0, tvav = 0, proc_tvav = 0 WHERE id_gestiune NOT in (select id_gestiune from crsIdVanzare)
		*!*			USE IN crsIdVanzare
		*!*		ENDIF
		
		*!*	ELSE
		*!*		SELECT rul_temp
		*!*		APPEND FROM DBF(lcSelRul)
		*!*	ENDIF
		
		*!*	IF INLIST(oset.model, 5, 6) AND USED('crsTransfer') && TRANSFER, RETUR TRANSFER
		*!*		SELECT rul_temp
		*!*		APPEND FROM DBF('crsTransfer')
		*!*	ENDIF
		
		*!*	SELECT rul_temp
		*!*	APPEND FROM DBF(lcSelRul)
		
		*!*	modificare	20.04.2007 & 04.05.2007 & 09.05.2007
		Do Case
		Case Inlist(oset.id_set,61,62,63,226,258)
			Select actactan
			If oset.cursval
				Calculate Sum(suma) To pnBazaValProd For Alltrim(scc)= '345'
				Calculate Sum(suma) To pnBazaVal341 For Alltrim(scc)= '341'
				Calculate Sum(suma) To pnBazaVal346 For Alltrim(scc)= '346'		
				Calculate Sum(suma) To pnBazaValAmb For Alltrim(scc) = '381'
				pnBazaVProd = pnBazaValProd
				pnBazaVAmb = pnBazaValAmb
				pnBazaV341 = pnBazaVal341
				pnBazaV346 = pnBazaVal346
			Else
				Calculate Sum(suma) To pnBazaVProd For Alltrim(scc)= '345'
				Calculate Sum(suma) To pnBazaVAmb For Alltrim(scc) = '381'
				Calculate Sum(suma) To pnBazaV341 For Alltrim(scc)= '341'
				Calculate Sum(suma) To pnBazaV346 For Alltrim(scc)= '346'		
			Endif
		
			Replace suma With suma - pnBazaVProd - pnBazaVAmb - pnBazaV341 - pnBazaV346  For Alltrim(SCD) = '4111' And Alltrim(scc) = '707'
		*!*	19.01.2015: 701-> 7015	
		*!*		Replace suma With pnBazaVProd + pnBazaV341 + pnBazaV346  For Alltrim(SCD) = '4111' And Alltrim(scc) = '701'
			Replace suma With pnBazaVProd + pnBazaV341 + pnBazaV346  For Alltrim(SCD) = '4111' And Alltrim(scc) = '7015'
		*!*	19.01.2015: 701-> 7015	^
			
			Replace SCD With '711',suma With pnBazaVProd For Alltrim(SCD) = '607' And Alltrim(scc) = '345'
			Replace SCD With '711',suma With pnBazaV341 For Alltrim(SCD) = '607' And Alltrim(scc) = '341'
			Replace SCD With '711',suma With pnBazaV346 For Alltrim(SCD) = '607' And Alltrim(scc) = '346'	
			Replace scc With '348' For INLIST(Alltrim(SCD),'341','345','346') And Alltrim(scc) = '378'
			Replace SCD With '348',scc With '711' For Alltrim(SCD) = '378' And INLIST(Alltrim(scc),'341','345','346')
		
			Replace suma With pnBazaVAmb For Alltrim(SCD) = '4111' And Alltrim(scc) = '708'
			Replace SCD With '608' For Alltrim(SCD) = '607' And Alltrim(scc) = '381'
			Replace scc With '388' For Alltrim(SCD) = '381' And Alltrim(scc) = '378'
			Replace SCD With '388' For Alltrim(SCD) = '378' And Alltrim(scc) = '381'
		
			Delete For suma = 0
		Case Inlist(oset.id_set,79,83,206,225)
			Select actactan
			Replace scc With '711' For Alltrim(SCD) = '348'
		*!* modificare 22.05.2007
		Case oset.id_set = 218  &&	diferenta de pret
			Select (lcSelRul)
			Replace All pretv With 0,tvav With 0,proc_tvav With 0,procent With 0
			Select actactan
			Replace id_gestin With 0,gestin With '' For nr_nota = 2
		*!*		Replace id_gestin With id_gestout, gestin With gestout,id_gestout With 0,gestout With '',scc WITH '711' For nr_nota = 4
		*!*		Replace scc WITH '711' For nr_nota = 4
			Replace SCD With '348' For nr_nota = 2 And SCD <> '381'
			Replace SCD With '388' For nr_nota = 2 And SCD = '381'
			Replace scc With '388' For nr_nota = 1 And SCD = '381'
		*!* modificare 22.05.2007 ^
		*!* modificare 16.08.2007
		Case INLIST(oset.id_set,53,213,57,58)
			Select actactan
			Replace scd With '607' For scc = '371'
			Replace scd With '711' For scc = '345'		&&	modificare 03.10.2007
		*!* modificare 16.08.2007 ^
		*!*	modificare	v 2.0.6
		*!* modificare v 2.0.13
		*!* modificare v 2.0.15 - protocol
		Case InList(oset.id_set, 230, 232, 233,261)
			Select actactan
			Replace suma With suma * (-1) For nr_nota = 1
		*!* modificare v 2.0.15 ^	
		*!* modificare v 2.0.13 ^	
		*!*	modificare	v 2.0.6 ^
		Endcase
		*!*	modificare ^
		
		&& ordonez notele contabile in ACTACTANSELECT actactan
		Select actactan
		
		Sum suma To lnSume
		
		If lnSume <> 0
			lcCondDele = [!(suma = 0 and !(((left(scd,1) = '3' and left(scc,2) = '40') OR (left(scd,2) = '41' and left(scc,1) = '7')) AND proc_tva # 1))]
		Else
			lcCondDele = [suma = 0 AND nr_nota = 1 ]
		Endif
		Select * From actactan Into Cursor crsActActan Where &lcCondDele Or Inlist(id_set, 89, 210, 211, 212) Order By nr_nota NOFILTER Readwrite
		
		Select actactan
		Delete From actactan
		Append From Dbf('crsactactan')
		If Used('crsactactan')
			Use In crsActActan
		Endif
		
		*** && completare analitice
		
		Select actactan
		Scan For Empty(Nvl(ascd,''))
			Scatter Name loActactan
			If Type('loActactan.cont') = 'U'
				x = AddProperty(loActactan,'cont',loActactan.SCD)
			Endif
			If oset.model = 2 And Type('loActactan.id_gestiune') = 'U'              && NIR
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestin)
			Endif
			If Inlist(oset.model, 3, 4) And Type('loActactan.id_gestiune') = 'U'    && BON, RETUR
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestout)
			Endif
			loActactan.ascd = This.assign_analitic(loActactan.SCD,This.cobj,'loActactan')
			Replace ascd With loActactan.ascd
			Select actactan
		Endscan
		Select actactan
		Scan For Empty(Nvl(ascc,''))
			Scatter Name loActactan
			If Type('loActactan.cont') = 'U'
				x = AddProperty(loActactan,'cont',loActactan.scc)
			Endif
			If oset.model = 2 And Type('loActactan.id_gestiune') = 'U'              && NIR
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestin)
			Endif
			If Inlist(oset.model, 3, 4) And Type('loActactan.id_gestiune') = 'U'    && BON, RETUR
				x = AddProperty(loActactan,'id_gestiune',loActactan.id_gestout)
			Endif
			loActactan.ascc = This.assign_analitic(loActactan.scc,This.cobj,'loActactan')
			Replace ascc With loActactan.ascc
			Select actactan
		Endscan
		
		If Used('rul_temp_OBINV')
			Use In RUL_TEMP_OBINV
		Endif
		
		Select * From rul_temp Where Cont = gcContObinv And !Deleted() Into Cursor RUL_TEMP_OBINV NOFILTER Readwrite
		Select rul_temp
		Delete All For Cont = gcContObinv
		
		If gnCMP = 1 And oset.model = 2 && NIR
			Thisform.analiza_cmp('rul_temp', 'actactan')
		*!*	modificare 24.11.2006
		Else
			Select rul_temp
			Replace id_tip_rulaj With oset.id_tip_rul For id_tip_rulaj = 0
		*!*	modificare 24.11.2006 ^
		Endif
		
		If Type('loActactan') = 'O'
			Release loActactan
		Endif
		
		Do Case
		Case oset.id_set=69
		*!*	modificare 07.03.2006	&&	24.02.2007
			Select actactan
			Calculate Max(proc_tva) To lnMaxProcTva
			Calculate Min(id_jtva_coloana) For proc_tva = lnMaxProcTva To lnIdJtvaColoana
			Scan For Left(SCD,3)='411' Or Left(scc,3)='411'
				If proc_tva=0
					Replace proc_tva With lnMaxProcTva,id_jtva_coloana With lnIdJtvaColoana
				Endif
			Endscan
		*!*	sfarsit modificare 07.03.2006
		Case  oset.id_set = 213
		*!*	modificare 12.02.2007	(bon de consum pe lucrari in curs de executie la Materii prime si materiale)
			Select rul_temp
			Replace All pretv With ROUND(Pret,gnPc)		&&	modificare 14.09.2007
		*!*	modificare 12.02.2007 ^
		*!*	modificare	v 2.0.6
		Case Inlist(oset.id_set,215,216,257)
			Select (lcSelRul)
			Replace All id_gestiunec With poAct.id_gestout,id_gestout with poAct.id_gestout,gestout With poAct.gestout
			Select actactan
			Replace All id_gestout With poAct.id_gestout,gestout With poAct.gestout
		*!*	modificare	v 2.0.6	^
		Endcase
		
		Select rul_temp
		Locate For Empty(Id_gestiune)
		If Found()
			aMessagebox('Nu ati ales gestiunea!',48,"Atentie")
			Return .F.
		Endif
		
		Select RUL_TEMP_OBINV
		Locate For Empty(Id_gestiune)
		If Found()
			aMessagebox('Nu ati ales gestiunea!',48,"Atentie")
			Return .F.
		Endif
		
		If oset.productie
			If Alltrim(Upper(oset.formproduc))='FRM_ALEGE_PROD_CANT'
				Select a.*, Recno() As ninreg ;
					FROM actactan a ;
					WHERE Substr(scc,1,1)='3' And Alltrim(scc)<>'301' ;
					INTO Cursor cModificari
		
				Select cModificari
				Scan
					Scatter Name loLinie
					lcSCC = Alltrim(scc)
					lnInreg = ninreg
					Select actactan
					Replace scc With lcSCC, SCD With '301' For Recno() = lnInreg
					Append Blank
					loLinie.SCD = '601'
					loLinie.scc = '301'
					Gather Name loLinie
					Select cModificari
				Endscan
		
				If Used('cModificari')
					Use In cModificari
				Endif
			Endif
		Endif
		
		*!* 02.06.2008
		*!* completez partenerii corespondenti pentru cont-gestin, cont-gestout
		lcSql = [Select cont, id_gestiune, id_part, denumire from vasociere_parteneri_gestiuni]
		lnSucces = goExecutor.oExecute(lcSql, "crsGestiuniParteneri")
		If lnSucces < 0
			AMessageBox(goExecutor.oExecute,0+16,"Eroare")
		Else
			Select actactan
			Scan FOR Empty(ID_PARTD) OR Empty(ID_PARTC)
				Scatter name loRec
				If Empty(actactan.id_partd)
					Select crsGestiuniParteneri
					Locate for Alltrim(cont) == Alltrim(loRec.scd) and id_gestiune = Iif(!Empty(loRec.id_gestin), loRec.id_gestin, loRec.id_gestout)
					If Found()
						Replace id_partd with crsGestiuniParteneri.id_part, partd with crsGestiuniParteneri.denumire in actactan
					EndIf 
				EndIf 	
				If Empty(actactan.id_partc)
					Select crsGestiuniParteneri
					Locate for Alltrim(cont) == Alltrim(loRec.scc) and id_gestiune = Iif(!Empty(loRec.id_gestout), loRec.id_gestout, loRec.id_gestin)
					If Found()
						Replace id_partc with crsGestiuniParteneri.id_part, partc with crsGestiuniParteneri.denumire in actactan
					EndIf 
				EndIf 			
				
			EndScan 
			Use in (Select('crsGestiuniParteneri'))
		EndIf 	
		
		Select actactan
		Go Top
		
		Return .T.
		
	ENDPROC

	PROCEDURE intrare_produs
		Select rul_temp
		Append Blank
		Replace id_articol With pnId_articol, ;
			denumire With pcDenumire, ;
			cant With pnCant, ;
			pret With ROUND(Thisform.ntotal/pnCant,gnPPret), ;
			id_gestiune With pnId_gestiune, nume_gestiune With pcGestiune, ;
			id_gestin With pnId_gestiune, gestout With pcGestiune, ;
			cont With pcCont_articol, ;
			nnir With poact.nnir, ;
			dataact With poact.dataact, ;
			datain With poact.dataact, ;
			id_set With poact.id_set
		
		
	ENDPROC

	PROCEDURE KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl
		
		LOCAL lcCtrGrid, lcCtrCriteriu, lcControl
		lcCtrGrid = []
		lcCtrCriteriu = []
		
		lcControl = UPPER(THIS.ACTIVECONTROL.NAME)
		IF lcControl = '_GRID1'
			lcCtrGrid = UPPER(THIS.ACTIVECONTROL.COMMENT)
		ENDIF
		
		IF lcControl = 'CRITERIU'
			lcCtrCriteriu = UPPER(THIS.ACTIVECONTROL.COMMENT)
		ENDIF
		
		DO CASE
			CASE nKeyCode = 13 AND 'GRD_ST' $ lcCtrGrid
				NODEFAULT
				THISFORM.urmator1.comMAND1.SETFOCUS
		
			CASE nKeyCode = 13 AND 'GRD_DR' $ lcCtrGrid
				NODEFAULT
				THISFORM.ct_grid_search1.Cb_tx_cautare1.TEXT.SETFOCUS
		
			CASE (nKeyCode >=33 AND nKeyCode <=122) AND ('CRITERIU_ST' $ lcCtrCriteriu OR 'GRD_ST' $ lcCtrGrid)
				NODEFAULT
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE = ALLTRIM(THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE) + CHR(nKeyCode)
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
		
			CASE (nKeyCode = 127) AND ('CRITERIU_ST' $ lcCtrCriteriu OR 'GRD_ST' $ lcCtrGrid) && backspace
				NODEFAULT
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE = LEFT(ALLTRIM(THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE),LEN(ALLTRIM(THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.VALUE))-1)
				THIS.ct_grid_search1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
		
			CASE (nKeyCode >=33 AND nKeyCode <=122) AND ('CRITERIU_DR' $ lcCtrCriteriu OR 'GRD_DR' $ lcCtrGrid)
				NODEFAULT
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE = ALLTRIM(THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE) + CHR(nKeyCode)
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
		
			CASE (nKeyCode = 127) AND ('CRITERIU_DR' $ lcCtrCriteriu OR 'GRD_DR' $ lcCtrGrid) && backspace
				NODEFAULT
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE = LEFT(ALLTRIM(THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE),LEN(ALLTRIM(THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.VALUE))-1)
				THIS.ct_grid_order1.Cb_tx_cautare1.TEXT.SETFOCUS
				KEYBOARD '{END}'
			CASE INLIST(nKeyCode, 13, 9, 4, 24) AND '_CBBASE1'$lcControl
				NODEFAULT 
				thisform.ct_grid_search1.cb_tx_cautare1.text.SetFocus
		 
			OTHERWISE
				DODEFAULT(nKeyCode, nShiftAltCtrl)
		ENDCASE
		
	ENDPROC

	PROCEDURE Release
		lcSelRul = this.ct_grid_order1.cnumecursor 
		lcSelSt = this.ct_grid_search1.cnumecursor 
		IF USED(lcSelRul)
			USE IN (lcSelRul)
		ENDIF 
		IF USED(lcSelSt)
			USE IN (lcSelSt)
		ENDIF 
		IF USED('crsTransfer')
			USE IN crsTransfer
		ENDIF 
	ENDPROC

	PROCEDURE Show
		Lparameters nStyle
		lcSelRul = This.ct_grid_order1.cnumecursor
		This.lbTotal.Caption = 'TOTAL ' + This.CTip_frm
		This.ct_grid_order1.initializare(.T.)
		This.ct_grid_search1.initializare(.T.)
		This.calcul_sume(lcSelRul)
		This.ct_grid_search1.cb_tx_cautare1.SetFocus
		
		If Inlist(poact.id_set,105,106)
			Thisform.ct_grid_search1.cboListe.Visible = .T.
			Thisform.ct_grid_search1.lb_listePreturi.Visible = .T.
		Endif
		
		If oxset.cursval
			With Thisform.ct_factura2
				lcObj = Thisform.cobj
				.lb_valuta.Caption = [(] + &lcObj..nume_val_vanz + [)]
				With .lb_curs
					.Caption = [Curs ] + Dtoc(&lcObj..v8) + [ : ] + Alltrim(Str(&lcObj..Curs,14,4))
					.AutoSize = .T.
				Endwith
			Endwith
		Endif
		
		If oset.productie And INLIST(oset.id_set,26003,26004)	&&	modificare 17.10.2007
			Thisform.container_valoare_decontata1.Visible = .T.
		Endif
		
		*!*	modificare	v	2.0.8
		*!* modificare v 2.0.13
		*!* modificare v 2.0.15 - protocol
		If InList(oset.id_set,75,216,230,232,233,257,261)
			thisform.lb_totalctva.Visible = .T.
			thisform.tx_totalctva.Visible = .T.
		EndIf
		*!* modificare v 2.0.15 ^
		*!* modificare v 2.0.13 ^
		*!*	modificare	v	2.0.8	^
		
		DoDefault(nStyle)
		
	ENDPROC

	PROCEDURE Ct_discount1.Init
		Select jtva_coloane
		*!*	Locate For proc_tva = 1.00 And procent = 0
		Locate For id_jtva_coloana = oSet.id_jtax
		If !Found()
			Go Top
		Endif
		This.lb_explicatie_tva.Caption = Alltrim(Upper(denumire))
		lnProc_tva = (cota_tva + 100)/ 100
		lnproc = cota_tva
		This.pntva = lnProc_tva
		This.nid_jtva_coloana = id_jtva_coloana
		This.nid_tva = jtva_coloane.id_tva
		This.cotaTva.ListIndex = Recno()
		
	ENDPROC

	PROCEDURE Ct_discount1.Refresh
		DODEFAULT()
		lcSelRul = thisform.ct_grid_order1.cnumecursor 
		this.Parent.calcul_sume(lcSelRul)
	ENDPROC

	PROCEDURE Ct_grid_order1.Cb_tx_gestin._CBBASE1.LostFocus
		SELECT nom_gestiuni
		pcobj.id_gestin = id_GESTiune
		pcobj.gestin = nume_gestiune
		pcObj.cgest = cgest
		pcobj.id_GESTiune = id_GESTiune
		pcobj.nume_gestiune = nume_gestiune
	ENDPROC

	PROCEDURE Ct_grid_search1.cboListe.Init
		IF INLIST(poact.id_set,105,106)
			SELECT cListePret
			LOCATE FOR id_pol = poact.id_pol
			this.Value = cListePret.nume_lista_preturi
			this.Refresh 
		ENDIF 
		
	ENDPROC

	PROCEDURE Ct_grid_search1.cboListe.Valid
		pnId_lista = cListePret.id_pol
		
		SELECT cListePret
		pcobj.id_pol = cListePret.id_pol
		thisform.ct_GRID_SEARCH1.initializare(.T.)
		thisform.ct_grid_search1.cb_tx_cautare1.text.SetFocus
		
	ENDPROC

	PROCEDURE Ct_grid_search1.Cb_tx_gestout._CBBASE1.Valid
		Select nom_gestiuni
		pcobj.id_gestout = id_GESTiune
		pcobj.gestout = nume_gestiune
		pcobj.cgest = cgest
		pcobj.id_GESTiune = id_GESTiune
		pcobj.nume_gestiune = nume_gestiune
		Thisform.ct_GRID_SEARCH1.initializare(.T.,.T.)
		This.Parent.Parent.cb_tx_cautare1.Text.SetFocus
	ENDPROC

	PROCEDURE Lb_titlu_alb_b121.Init
		If Type('oxset.nume_set') # 'U'
			This.Caption = Proper(Alltrim(oxset.nume_set))
		Endif
		This.Caption = This.Caption + [ ( Nr. document : ] + Alltrim(Nvl(poAct.serie_act,[])) + [ ] + ;
			TRANSFORM(poAct.nract,get_mask(14,0)) + [ ) ]
	ENDPROC

	PROCEDURE Urmator1.Command1.Click
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		*!*		Model =-1 : Nota fara contabilizare
		*!*		Model = 1 : Nota simpla cu contabilizare
		*!*		Model = 2 : NIR
		*!*		Model = 3 : BON/FACTURA VANZARE
		*!*		Model = 4 : Retur BON/FACTURA VANZARE
		*!*		Model = 5 : Transfer
		*!*		Model = 6 : Retur Transfer
		*!*		Model = 7 : Diferenta de pret
		
		*!*		Param1 = 1 : En-detail
		*!*		Param1 = 2 : En-gros
		*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*	*!*
		Private poPreturi
		poPreturi = CreateObject("empty")
		AddProperty(poPreturi,"pretv", 0)
		AddProperty(poPreturi,"tvav", 0)
		AddProperty(poPreturi,"pretvtva", 0)
		
		Local lnNIRPRETLISTAMOD
		If Type('gnNIRPRETLISTAMOD') <> 'U'
			lnNIRPRETLISTAMOD = gnNIRPRETLISTAMOD
		Else 
			lnNIRPRETLISTAMOD = 0
		EndIf 	
		Local lnPretfTva, lnPretvTva, lnListaPreturiCuTva
		lnPretfTva = 0
		lnPretvTva = 0
		lnListaPreturiCuTva = 1 && daca lista de preturi are preturile cu tva id_set = 231 nir mf la pv cu modificarea listei de preturi
		
		lcSelRul = THISFORM.ct_grid_order1.cnumecursor
		
		*!*	modificare 22.08.2007
		*!*	 La toate conditiile unde era id_articol, am adaugat si NVL(serie,'') , in afara de politicile de preturi si reteta.
		
		lcIde = [T]
		lcIde = lcIde + ',' + IIF(oset.factura AND oset.model = 2, 'F', '')
		lcIde = lcIde + ',' + IIF(oset.adaos AND (oset.param1 = 1 OR oset.model = 2), 'A,X','')
		lcIde = lcIde + ',' + IIF(oset.discount, 'D','')
		lcIde = lcIde + ',' + IIF(INLIST(oset.model,2), 'N', IIF(INLIST(oset.model, 3, 4, 5, 6, 7), 'B', ''))
		lcIde = IIF(oset.model = 7, lcIde + ',X' , lcIde)
		
		lnProcDisc = IIF(oset.discount,THISFORM.ct_discount1.proc_discount ,0)
		*!*	modificare 22.06
		*!*	lnProcAdaos = IIF(oset.adaos,thisform.ct_adaos1.proc_adaos,0)
		lnProcAdaos = IIF(oset.adaos,IIF(THISFORM.ct_adaos1.proc_adaos<-9999999,0,THISFORM.ct_adaos1.proc_adaos),0)
		*!*	^
		
		SELECT cursor_curent1
		SCATTER NAME oStg
		
		If Empty(oStg.Cont)
			amessagebox('Nu s-a selectat nici un reper! Repetati selectia!',48,"Atentie")
			Release oStg
			Thisform.ct_grid_search1._GRID1.SetFocus
			Return
		Endif
		
		*!*	If oSet.model > 2  And !Empty(NVL(oStg.id_rul_aux,0))
		*!*		amessagebox("Operatiile asupra acestui reper se pot efectua doar din programul ROAVIN!",48,"Atentie")
		*!*		Release oStg
		*!*		Thisform.ct_grid_search1._GRID1.SetFocus
		*!*		Return
		*!*	Endif
		
		*!* DNF
		SELECT (lcSelRul)
		SCATTER NAME orul BLANK
		IF !PEMSTATUS(orul,'dnf',5)
			ADDPROPERTY(orul,'dnf',00000)
			IF PEMSTATUS(oStg,'dnf',5)
				orul.DNF= oStg.DNF
			ENDIF
		ENDIF
		
		*!* MODIFICAT 11.04.2006
		*!* MARIUS.MUTU - SA SE POATA SCOATE DIN STOC DE MAI MULTE ORI ACEEASI CANTITATE LA OB INV IN FOLOSINTA CAND TRANSFER, CASARE DIN FOLOSINTA
		IF !INLIST(oset.id_set,210,211,212,89,70)
			IF 'B' $ lcIde
				SELE (lcSelRul)
				IF gnTipGest # 6
					SELECT SUM(cante) AS cante, id_articol, NVL(serie,'') as serie FROM (lcSelRul) ;
						WITH (BUFFERING = .T.) WHERE id_articol = oStg.id_articol AND PRET =oStg.PRET ;
						AND id_gestout = oStg.id_gestiune AND NVL(serie,'') = NVL(oStg.serie,'') ;
						GROUP BY id_articol,serie INTO CURSOR crsCant
					*!*			LOCATE FOR id_articol = ostg.id_articol AND pret =ostg.pret AND id_gestout = ostg.id_gestiune   && id_gestout in loc de id_gestiune pt ca la transfer modific id_gestiune (inainte_de_do_termin)
				ELSE
					SELECT SUM(cante) AS cante, id_articol,NVL(serie,'') as serie FROM (lcSelRul) ;
						WITH (BUFFERING = .T.) WHERE id_articol = oStg.id_articol AND pretv =oStg.pretv ;
						AND id_gestout = oStg.id_gestiune AND PRET =oStg.PRET AND NVL(serie,'') = NVL(oStg.serie,'') ;
						GROUP BY id_articol,serie INTO CURSOR crsCant
					*!*			LOCATE FOR id_articol = ostg.id_articol AND pretv =ostg.pretv AND id_gestout = ostg.id_gestiune AND pret =ostg.pret  && id_gestout in loc de id_gestiune pt ca la transfer modific id_gestiune (inainte_de_do_termin)
				ENDIF
		
				SELECT crsCant
				LOCATE
				lnCant = cante
				*!*			IF FOUND()
				IF RECCOUNT('crsCant')  > 0
					amessagebox('Daca doriti o cantitate diferita, stergeti acest reper si repetati selectia.',0+64,"Info")
					THISFORM.ct_grid_search1._GRID1.SETFOCUS
					USE IN crsCant
					RETURN
				ENDIF
				USE IN crsCant
			ENDIF
		ELSE
			&& scoatere din stoc obiecte de inventar
			IF 'B' $ lcIde
				SELE (lcSelRul)
		
				SELECT SUM(cante) AS cante, id_articol, NVL(serie,'') as serie ;
					FROM (lcSelRul) WITH (BUFFERING = .T.) ;
					WHERE id_articol = oStg.id_articol AND PRET =oStg.PRET AND id_gestout = oStg.id_gestiune ;
					AND id_responsabil = oStg.id_responsabil AND datapif = oStg.datapif AND NVL(serie,'') = NVL(oStg.serie,'') ;
					GROUP BY id_articol,serie INTO CURSOR crsCant
		
				SELECT crsCant
				LOCATE
				lnCant = cante
				IF RECCOUNT('crsCant')  > 0
					amessagebox('Daca doriti o cantitate diferita, stergeti acest reper si repetati selectia.',64,"Info")
					* THISFORM.ct_grid_search1._GRID1.SETFOCUS
					thisform.ct_grid_search1.cb_tx_cautare1.text.SetFocus
					USE IN crsCant
					RETURN
				ENDIF
				USE IN crsCant
			ENDIF
		
		ENDIF
		
		*!*	modificare	03.10.2007
		If Inlist(oxset.model,4,6)	&&	Retur
			lcObiect = Thisform.cobj
			&lcObiect..id_gestout = oStg.id_gestiune
			&lcObiect..gestout = ALLTRIM(oStg.nume_gestiune)
		Endif
		*!*	modificare	03.10.2007	^
		
		THISFORM.assign_values('orul',THISFORM.cobj,'oStg')
		
		IF TYPE('orul.datapif') # 'U' AND TYPE('orul.datapif') = 'T' && pentru ob. inv. in folosinta
			orul.datapif = TTOD(orul.datapif)
		ENDIF
		
		IF INLIST(oset.model,3,4) AND oset.param1 = 1  && bon/retur + factura + en-detail
			lnPretvTva = orul.pretv + orul.tvav  && pret vanzare cu TVA
			*!*	modificare 22.06
			lnProcAdaos = IIF(orul.procent<>0,orul.procent,lnProcAdaos)
			*!*	^
		Else
			*!* 09.06.2008
			*!*	231 = roagest - nir marfa la pretv cu lista de preturi
			*!* 247  = roagest - nir marfa la pretv cu lista de preturi gestiune hibrid 23.10.2008
			*!* 266 roagest - mf pret de ach * > factura nesosita - pret de lista ** 19.05.2010	
			IF INLIST(oset.id_set,105,106,231,247,266) && 105,106 - roafacturare - NIR de marfa la pret de vanzare
				lcSql = [ select pretftva, pretctva from vcrm_politici_pret_art where id_pol=] + ALLTRIM(STR(poact.id_pol))+;
					[ and id_articol =] + ALLTRIM(STR(oStg.id_articol))
		
				lnSucces=goExecutor.oExecute(lcSql,'crsPret')
				IF lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,'Eroare')
				EndIf
			
				SELECT crsPret
				lnPretfTva = pretftva
				lnPretvTva = pretctva
				IF USED('crsPret')
					USE IN crsPret
				ENDIF
		
				Private pnReturnValue
				pnReturnValue = 0
				lnSucces = goExecutor.oSelect2Value("select preturi_cu_tva from vcrm_politici_preturi where id_pol = " + ALLTRIM(STR(poact.id_pol)), @pnReturnValue)
				IF lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,'Eroare')
				Else 
					lnListaPreturiCuTva	= pnReturnValue
				EndIf		
			ELSE
				lnPretvTva = 0
			EndIf
			*!* 09.06.2008
		ENDIF
		
		IF oset.id_set = 104
			PRIVATE pnImputare
			STORE 0 TO pnImputare
		
			IF gnImputare = 1 && pretul maxim din stoc
				lcSql=[select MAX(pret) as pretMax from (select pack_sesiune.suma_ron(pret, an, luna) as pret from ] + ;
					[(select pret, an, luna from stoc where id_articol = ] + +ALLTRIM(STR(orul.id_articol))+ ;
					[ and NVL(serie,'x_x_x') = '] + NVL(orul.serie,'x_x_x') + [' ] + gcCondSucursala + [))]
		
				lnSucces=goExecutor.oExecute(lcSql,'crsPretMax')
				IF lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,'Eroare')
				ENDIF
		
				SELECT crsPretMax
				orul.pretv = pretMax
				IF ISNULL(orul.pretv)
					orul.pretv = 0
				ENDIF
		
				IF USED('crsPretMax')
					USE IN crsPretMax
				ENDIF
			ENDIF
		ENDIF
		
		IF EMPTY(THISFORM.cfrm_ceredate)
			RETURN
		ENDIF
		
		IF INLIST(oset.id_set,211) && TRANSFER MAGAZIE OB INV IN FOLOSINTA - CATRE GESTIUNE OB INV IN FOL PE UN RESPONSABIL
			orul.id_responsabil = 0
			orul.NRESP = ''
		ENDIF
		
		lcForm = ALLTRIM(THISFORM.cfrm_ceredate)
		onir = CREATEOBJECT(lcForm)
		onir.bVizualizare = lcIde
		onir.cobj = orul
		*onir.cParentObj = thisform.cobj
		onir.pretvtva = lnPretvTva
		
		*!* 09.06.2008
		*!* 231 - nir mf pretv cu modificarea listei de preturi
		*!* 247  = roagest - nir marfa la pretv cu lista de preturi gestiune hibrid 23.10.2008
		*!* 266 roagest - mf pret de ach * > factura nesosita - pret de lista ** 19.05.2010
		IF INLIST(oset.id_set,105,106,231,247,266)
			onir.cobj.pretv = lnPretfTva
			onir.cobj.tvav = lnPretvTva - lnPretfTva
			&& v 2.0.14 din 11iun2008 - preluare preturi din rul de pe ultima factura de achizitie, cautarea se face in ultimele 2 luni
			IF INLIST(oset.id_set,231,247,266)
				*!* v 2.0.18 (ordonare an desc, luna desc, dataora desc, cant <> 0)
				lcSql = [select a.* from  (select a.dataora,a.pret,a.tva, a.tvav,a.pretv,a.PRETV+a.TVAV as pretvtva ]+;
		  				[ from rul a where a.ID_ARTICOL = ]+Alltrim(Str(orul.id_articol)) + [ and a.sters = 0 and a.cant<>0  and a.id_tip_rulaj = 0]+;
						[ and an*12+luna between ]+ Alltrim(Str(gnAn*12+gnluna-1))+[  and ]+ Alltrim(Str(gnAn*12+gnluna)) +;
		 				[ order by a.an desc, a.luna desc, a.dataora desc) a where rownum = 1]
				*!* v 2.0.18 ^
				lnSucces=goExecutor.oExecute(lcSql,'crsPretUltim')
				IF lnSucces < 0
					amessagebox(goExecutor.cEroare,0+16,'Eroare')
				Else 		
					Select crsPretUltim
					If Reccount() > 0
						onir.pretu_factura = crsPretUltim.pret
						onir.cobj.pret = crsPretUltim.pret
						onir.cobj.tva = crsPretUltim.tva	
						&& suprascriu pretul de vanzare din lista doar daca pe nir am pretul <> 0 
						If crsPretUltim.pretv <> 0
							onir.cobj.pretv = crsPretUltim.pretv
							onir.cobj.tvav = crsPretUltim.tvav	
							onir.pretvtva = crsPretUltim.pretvtva
						EndIf 
						
					EndIf 	
					Use in 	crsPretUltim
				EndIf 
			&& v 2.0.14 din 11iun2008 ^
			EndIf 
		ENDIF
		*!* 09.06.2008 ^
		
		onir.cTitlu = ALLTRIM(NVL(oStg.denumire,'')) + [-] + ALLTRIM(NVL(oStg.codmat,''))
		onir.item2.text_item1.READONLY =  IIF(oset.model = 2, .F., .T.)
		
		IF oset.param1 = 1 AND (oset.model = 4 OR gnTipGest = 6) && facturi retur / vanzare marfa la pret de vanzare en-detail - blochez pretul de vanzare
			onir.BlochezPretV = .T.
			onir.proc_tvav = orul.proc_tvav
			onir.proc_adaos = lnProcAdaos
		ENDIF
		
		Do Case
		CASE oset.model = 7  && ( oset.id_set = 218 )
			onir.item9.label_item1.Caption = 'Pret nou fara TVA'
			onir.item9.text_item1.inputmask = get_mask(12,gnPPret)
		Case poact.id_set = 104 && RoaObInv - Imputare
			onir.item7.label_item1.Caption = 'Pret imputare cu TVA'
			onir.item8.label_item1.Caption = 'TVA imputare'
			onir.item9.label_item1.Caption = 'Pret imputare fara TVA'
		* onir.BlochezPretV = .T.
		Case poact.id_set = 26001 && ROAPRODUCTIE.PV_PRODUCTIE
			Local lnPret
			Store 0 To lnPret
		
			Private poPret
			Store '' To poPret
			Local lcschema, lcselect, lcFiltru, lcOrder, llAfiseaza, lcgroup, llModParam, lcFiltruOriginal
		
			lcschema = []
			lcselect = [select pret from vcrm_politici_pret_art]
			lcOrder = []
			lcFiltru = []
			llAfiseaza = .F.
			lcgroup = ""
			llModParam = .T.
			lcFiltruOriginal = [id_pol=] + ALLTRIM(STR(poact.id_pol)) + [ and id_articol=] + ALLTRIM(STR(oStg.id_articol))
		
			gencursor('poPret','crsPret',lcselect,lcFiltru,lcschema,lcOrder,llAfiseaza, lcgroup, llModParam, lcFiltruOriginal)
			poPret.ca_baza1.afisare()
		
			SELECT crsPret
			GO TOP
			lnPret = PRET
		
			IF USED('crsPret')
				USE IN crsPret
			ENDIF
		
			RELEASE poPret
		
			onir.cobj.PRET = lnPret
			onir.item2.label_item1.CAPTION = 'Pret unitar'
			onir.item2.text_item1.READONLY = .T.
			onir.item2.text_item1.TABSTOP = .F.
		
			LOCAL lcReteta, lnId_reteta
			STORE 0 TO lnId_reteta
			STORE '' TO lcReteta
		
			PRIVATE poReteta
			STORE '' TO poReteta
		
			lcschema = []
			lcselect = [select id_reteta, reteta from vnom_retetar]
			lcOrder = []
			lcFiltru = []
			llAfiseaza = .F.
			lcgroup = ""
			llModParam = .T.
			lcFiltruOriginal = [principala=1 and id_articol=]+ALLTRIM(STR(onir.cobj.id_articol))
			gencursor('poReteta','crsReteta',lcselect,lcFiltru,lcschema,lcOrder,llAfiseaza, lcgroup, llModParam, lcFiltruOriginal)
			poReteta.ca_baza1.afisare()
		
			SELECT crsReteta
			GO TOP
			lcReteta = ALLTRIM(reteta)
			lnId_reteta = id_reteta
		
			IF USED('crsReteta')
				USE IN crsReteta
			ENDIF
		
			RELEASE poReteta
		
			onir.cobj.reteta = lcReteta
			onir.cobj.id_reteta = lnId_reteta
		ENDCASE
		
		*onir.item4.text_item1.comment = onir.item4.text_item1.comment + IIF(INLIST(oset.model,3,4),[e],[]) && CANT sau CANTE
		onir.item4.text_item1.COMMENT = onir.item4.text_item1.COMMENT + IIF(LOWER(ALLTRIM(THISFORM.osel_dr.cantitate))=[cante],[e],[]) && CANT sau CANTE
		onir.proc_discount = lnProcDisc
		onir.proc_adaos = lnProcAdaos
		onir.SHOW(1)
		
		IF gnButon = 1
			lcCant = [orul.] + ALLTRIM(THISFORM.osel_dr.cantitate)
			IF TYPE('ostg.cantitate') # 'U' AND INLIST(oset.model, 3, 4, 5, 6, 7)  &&: bon, retur, transfer, retur transfer
				lnCantD = &lcCant
				lnCantD1 = &lcCant
				lnCantS = oStg.cantitate
		
				*!* MODIFICAT 11.04.2006
				*!* DOAR LA ID_SET = 210 (TRANSFER OB INV IN FOL CATRE MAI MULTI RESPONSABILI) AM PERMIS SA SE SCOATA DE MAI MULTE ORI ACELASI REPER
				*!* ADUN CANTITATEA DEJA IESITA LA CEA CURENTA
				lnCant = 0
				IF INLIST(oset.id_set,210,211,212,89)
					SELECT SUM(NVL(cant,0)) AS cant ;
						FROM (lcSelRul) WITH (BUFFERING = .T.);
						WHERE id_articol = oStg.id_articol AND PRET = oStg.PRET AND id_gestout = oStg.id_gestiune AND NVL(serie,'') = NVL(oStg.serie,'') ;
						INTO CURSOR crsCant
					SELECT crsCant
					CALCULATE SUM(cant) TO lnCant
					lnCantD = lnCantD + lnCant
					USE IN crsCant
				ENDIF
				IF ABS(lnCantD) > ABS(lnCantS) OR (SIGN(lnCantD1) * SIGN(lnCantS) < 0)
					lcTitlu = [Atentie]
					lcTip = [Avertizare]
					lcImagine = [exclam.ico]
					ofrm_eroare = CREATEOBJECT('frm_mesaj',lcTitlu,lcImagine,lcTip,"Cantitatea maxima existenta este:",oStg.cantitate)
					ofrm_eroare.SHOW(1)
					RELEASE ofrm_eroare
					&lcCant = oStg.cantitate - lnCant
				ENDIF
		
				*!* MODIFICAT 11.04.2006
				*!* NU ADAUG ARTICOLE FARA CANTITATE
				IF &lcCant = 0
					THISFORM.ct_grid_order1.cb_tx_gestin.SETFOCUS()
					RETURN
				ENDIF
			ENDIF
		
			DO case
			 CASE INLIST(oset.model, 4, 6)  && retur BON, retur TRANSFER
				&lcCant = -&lcCant
		     case oset.model = 2 && NIR
				SELECT (lcSelRul)
				orul.acont = THISFORM.assign_analitic(orul.CONT,THISFORM.cobj,'orul')
			ENDCASE
		
			IF INLIST(oset.model,5,6,7) && TRANSFER, RETUR TRANSFER, DIFERENTA DE PRET
				lcCantDr = LOWER(ALLTRIM(THISFORM.osel_dr.cantitate))
				lcCantTransf = [cant] + IIF(lcCantDr = [cante],[],[e])
				IF !USED('crsTransfer')
					SELECT *, 0000 AS rec, 0 AS nuInConturiX FROM (lcSelRul) INTO CURSOR crsTransfer WHERE 1=2 NOFILTER READWRITE
				ENDIF
				SELECT crsTransfer
				APPEND BLANK
				GATHER NAME pcObj
				GATHER NAME oStg
				REPLACE cant WITH 0, cante WITH 0
				REPLACE &lcCantTransf WITH &lcCant
				*REPLACE nuInConturiX WITH 1
				*!*	modificare 26.02.2007
				Do Case
				Case INLIST(oset.id_set,75,218)	&&	modificare 22.05.2007 : completez si pretv ca sa pot calcula adaosul
					Replace pretv With orul.pretv,tvav With orul.tvav,proc_Tvav With orul.proc_Tvav
				Case INLIST(oset.id_set, 207,254)
					orul.pretv = oStg.pretv
					orul.tvav = oStg.tvav
					orul.proc_tvav = oStg.proc_tvav
				Case oset.id_set = 89 && transfer intre persoane
					pcObj.id_gestin = orul.id_gestout
					pcObj.gestin = orul.id_gestout
					orul.id_gestin = orul.id_gestout
					orul.gestin = orul.gestout
				Endcase
		*!*			IF oset.id_set = 89 && transfer intre persoane
		*!*				pcObj.id_gestin = orul.id_gestout
		*!*				pcObj.gestin = orul.id_gestout
		*!*				orul.id_gestin = orul.id_gestout
		*!*				orul.gestin = orul.gestout
		*!*			ENDIF
				*!*	modificare 26.02.2007	^
				REPLACE id_gestin WITH orul.id_gestin, gestin WITH orul.gestin
				REPLACE id_gestout WITH orul.id_gestout, gestout WITH orul.gestout
				*!*			IF TYPE('orul.id_gestiune') = 'N' AND TYPE('crsTransfer.id_gestiunec') = 'N'
				*!*				REPLACE id_gestiunec WITH orul.id_gestiune
				*!*			ENDIF
				IF TYPE('orul.id_responsabil') = 'N' AND TYPE('crsTransfer.id_responsabilc') = 'N'
					REPLACE id_responsabilc WITH orul.id_responsabil
				ENDIF
			ENDIF
		
			IF oset.id_set = 104
				IF gnImputare = 1
					SELECT cursor_curent1
					IF DNF<>0
						uzura = (DNF-(dns_luni-IIF(!EMPTY(datapif) AND !ISNULL(datapif),((gnAn*12+gnLuna)-(YEAR(datapif)*12+MONTH(datapif))),0)))/DNF*100
					ELSE
						uzura = 0
					ENDIF
					DO CASE
						CASE pnImputare = 1 && procent
							orul.pret_imputare = ROUND((100 - uzura) * orul.pretv / 100,gnPC)
						CASE pnImputare = 2 && integral
							orul.pret_imputare = orul.pretv
						OTHERWISE
							orul.pret_imputare = orul.pretv
					ENDCASE
				ELSE
					orul.pret_imputare = orul.pretv
				ENDIF
			ENDIF
		
			SELECT (lcSelRul)
			APPEND BLANK
			GATHER NAME orul
			lnRecno = RECNO()
		
			*!*		IF TYPE('ostg.id_gestiune') = 'N'
			*!*			REPLACE id_gestiunec WITH ostg.id_gestiune
			*!*		ENDIF
			IF TYPE('ostg.id_responsabil') = 'N'
				REPLACE id_responsabilc WITH oStg.id_responsabil
			ENDIF
		
			*!* MODIFICAT 11.04.2006
			*!* MARIUS.MUTU - AM PUS RECNO('RUL_TEMP') IN CURSORUL DE TRANSFER - LA STERGERE SA POT STERGE SI LINIA CORESPONDENTA DIN CRSTRANSFER
			IF INLIST(oset.model,5,6,7) AND USED('crsTransfer') && TRANSFER, RETUR TRANSFER, DIFERENTA DE PRET
				SELECT crsTransfer
				REPLACE rec WITH lnRecno
			EndIf
			
			*!* 09.06.2008
			*!* 231 - nir mf pretv cu modificarea listei de preturi
			*!* daca pretul de vanzare este diferit de pretul de vanzare din lista
			*!* modific pretul de vanzare din lista
			&& 247  = roagest - nir marfa la pretv cu lista de preturi gestiune hibrid 23.10.2008
			*!* 266 roagest - mf pret de ach * > factura nesosita - pret de lista ** 19.05.2010	
			If INLIST(oset.id_set,231,247,266) and poPreturi.pretvtva <> lnPretvTva and lnNIRPRETLISTAMOD = 1	 
				lnPretftvaLista = poPreturi.pretv
				lnPretvtvaLista = poPreturi.pretvtva
				lnPretLista = Iif(lnListaPreturiCuTva = 1, lnPretvtvaLista, lnPretftvaLista)
				lcSql = [update crm_politici_pret_art set pret = ] + Alltrim(Str(lnPretLista,20,4)) + ;
					[, pretftva = ] + Alltrim(Str(lnPretftvaLista,20,4)) + [, pretctva = ] + Alltrim(Str(lnPretvtvaLista ,20,4)) + ;
					[ where id_pol=] + ALLTRIM(STR(poact.id_pol)) + [ and id_articol =] + ALLTRIM(STR(oStg.id_articol))
				lnSucces = goExecutor.oExecute(lcSql)
				If lnSucces < 0
					MessageBox(goExecutor.cEroare,0+16, 'Eroare')
				EndIf 
			EndIf 	
			*!* 09.06.2008 ^
		
			IF THISFORM.ct_grid_order1.cb_tx_gestin.VISIBLE
				THISFORM.ct_grid_order1.cb_tx_gestin._cbbase1.VALUE = orul.gestin
				THISFORM.ct_grid_order1.cb_tx_gestin._cbbase1.REFRESH
			ENDIF
			THISFORM.ct_grid_order1.actualizeaza_grid()
			THISFORM.ct_grid_order1._GRID1.AUTOFIT
		ELSE
			THISFORM.ct_grid_search1._GRID1.SETFOCUS
		ENDIF
		
		THISFORM.calcul_sume(lcSelRul)
		
		*!*	SELECT crsTransfer
		*!*	BROWSE
		*!*	SELECT (lcSelRul)
		*!*	BROWSE
		
		IF oset.productie AND INLIST(oset.id_set,26003,26004)	&& modificare 17.10.2007	AND ALLTRIM(UPPER(oset.formproduc))='FRM_ALEGE_SECTIE_COMANDA'
			pnValoareDecontata = thisform.nTotal 
			pnCheltuieliDirecte = thisform.nTotal - pnValoareDecontata                     
			thisform.container_valoare_decontata1.Refresh 
		ENDIF 
		
		RELEASE orul
		RELEASE oStg
		
	ENDPROC

	PROCEDURE _shape1.DblClick
		IF thisform.WindowState = 2
			thisform.WindowState = 0
		ELSE 
			thisform.WindowState = 2 
		ENDIF 
	ENDPROC

ENDDEFINE

DEFINE CLASS valoare2rulaj AS frm_termin_renunt OF "_frm_child.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="_shape3" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_facturi_transport" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdFacturiTransport" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_articole" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cmdArticole" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Clb_valoare_repartizat" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cbo_explicatieTVA" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="lb_explicatieTVA" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Caut_anluna1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="_label1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: calculvaloarerepartizat
		*m: do_cauta_articole
		*m: do_cauta_facturi_achizitie
		*m: do_cauta_facturi_transport
		*m: do_cauta_furnizor
		*m: make_rul_temp
		*p: cacont
		*p: ccont
		*p: cfurnizorname
		*p: clistaidarticole
		*p: clistaidfacturitransport
		*p: cnumefurnizor
		*p: cxmlarticole
		*p: cxmlfacturiachizitie
		*p: cxmlfacturitransport
		*p: ddata1
		*p: ddata2
		*p: nidfurnizor
		*p: nprocenttva
		*p: ntotalvaloarerepartizat
		*p: ofurnizor
	*</DefinedPropArrayMethod>

	*<PropValue>
		cacont = 
		Caption = "Form"
		ccont = 301
		cfurnizorname = 
		clistaidarticole = 
		clistaidfacturitransport = 
		cnumefurnizor = 
		cxmlarticole = 
		cxmlfacturiachizitie = 
		cxmlfacturitransport = 
		ddata1 = {}
		ddata2 = {}
		DoCreate = .T.
		Height = 178
		Name = "valoare2rulaj"
		nidfurnizor = 0
		nprocenttva = 0
		ntotalvaloarerepartizat = 0
		ofurnizor = .F.
		Width = 599
		_SHAPE1.Height = 29
		_SHAPE1.Left = 0
		_SHAPE1.Name = "_SHAPE1"
		_SHAPE1.Top = 0
		_SHAPE1.Width = 600
		_SHAPE1.ZOrderSet = 1
		_SHAPE2.Height = 29
		_SHAPE2.Left = 539
		_SHAPE2.Name = "_SHAPE2"
		_SHAPE2.Top = 0
		_SHAPE2.Width = 61
		_SHAPE2.ZOrderSet = 2
		LB_TITLU_ALB_B121.Caption = "Repartizare valori pe articole"
		LB_TITLU_ALB_B121.Name = "LB_TITLU_ALB_B121"
		LB_TITLU_ALB_B121.TabIndex = 10
		LB_TITLU_ALB_B121.ZOrderSet = 3
		BUT_TERMIN1.Left = 570
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 6
		BUT_TERMIN1.Top = 1
		BUT_TERMIN1.ZOrderSet = 4
		GRIDSORT1.Name = "GRIDSORT1"
		BUT_RENUNT1.Left = 541
		BUT_RENUNT1.Name = "BUT_RENUNT1"
		BUT_RENUNT1.TabIndex = 7
		BUT_RENUNT1.Top = 1
		BUT_RENUNT1.ZOrderSet = 6
	*</PropValue>

	ADD OBJECT '_label1' AS _label WITH ;
		Caption = "Luna intrari articole", ;
		Left = 21, ;
		Name = "_label1", ;
		TabIndex = 4, ;
		Top = 146, ;
		ZOrderSet = 15
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="label" />

	ADD OBJECT '_shape3' AS _shape WITH ;
		BackStyle = 0, ;
		Height = 29, ;
		Left = 13, ;
		Name = "_shape3", ;
		Top = 138, ;
		Width = 372, ;
		ZOrderSet = 0
		*< END OBJECT: ClassLib="_baza.vcx" BaseClass="shape" />

	ADD OBJECT 'Caut_anluna1' AS caut_anluna WITH ;
		Left = 226, ;
		Name = "Caut_anluna1", ;
		TabIndex = 12, ;
		ToolTipText = "Luna in care se cauta intrarile de articole pe care se repartizeaza valoarea facturilor", ;
		Top = 142, ;
		ZOrderSet = 14, ;
		cboan.Name = "cboan", ;
		cboluna.Name = "cboluna"
		*< END OBJECT: ClassLib="caut_ora.vcx" BaseClass="container" />

	ADD OBJECT 'cbo_explicatieTVA' AS combobox WITH ;
		BorderColor = 128,128,128, ;
		BorderStyle = 1, ;
		BoundTo = .T., ;
		ColumnCount = 1, ;
		ColumnLines = .F., ;
		ControlSource = "", ;
		FontSize = 10, ;
		Height = 20, ;
		InputMask = "", ;
		Left = 439, ;
		Name = "cbo_explicatieTVA", ;
		RowSource = "jtva_coloane.denumire,cota_tva,id_jtva_coloana", ;
		RowSourceType = 2, ;
		SpecialEffect = 1, ;
		Style = 2, ;
		TabIndex = 5, ;
		TabStop = .F., ;
		Top = 65, ;
		Width = 149, ;
		ZOrderSet = 12
		*< END OBJECT: BaseClass="combobox" />

	ADD OBJECT 'Clb_articole' AS clb_tx_simplu WITH ;
		Height = 29, ;
		Left = 13, ;
		Name = "Clb_articole", ;
		TabIndex = 3, ;
		Top = 110, ;
		Width = 372, ;
		ZOrderSet = 9, ;
		TEXT_SIMPLU1.Height = 23, ;
		TEXT_SIMPLU1.Left = 101, ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.ReadOnly = .T., ;
		TEXT_SIMPLU1.Top = 3, ;
		TEXT_SIMPLU1.Width = 265, ;
		LB_SIMPLU1.Caption = "Articole", ;
		LB_SIMPLU1.Name = "LB_SIMPLU1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Clb_facturi_transport' AS clb_tx_simplu WITH ;
		Height = 29, ;
		Left = 12, ;
		Name = "Clb_facturi_transport", ;
		TabIndex = 1, ;
		Top = 48, ;
		Width = 372, ;
		ZOrderSet = 7, ;
		TEXT_SIMPLU1.Height = 23, ;
		TEXT_SIMPLU1.Left = 132, ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.ReadOnly = .T., ;
		TEXT_SIMPLU1.Top = 3, ;
		TEXT_SIMPLU1.Width = 234, ;
		LB_SIMPLU1.Caption = "Facturi de repartizat", ;
		LB_SIMPLU1.Name = "LB_SIMPLU1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Clb_valoare_repartizat' AS clb_tx_simplu WITH ;
		Height = 29, ;
		Left = 12, ;
		Name = "Clb_valoare_repartizat", ;
		TabIndex = 2, ;
		Top = 76, ;
		Width = 372, ;
		ZOrderSet = 11, ;
		Text_simplu1.ControlSource = "thisform.nTotalValoareRepartizat", ;
		Text_simplu1.Format = "KR", ;
		Text_simplu1.Height = 23, ;
		Text_simplu1.InputMask = (get_mask(12,gnPc)), ;
		Text_simplu1.Left = 216, ;
		Text_simplu1.Name = "Text_simplu1", ;
		Text_simplu1.ReadOnly = .T., ;
		Text_simplu1.Top = 3, ;
		Text_simplu1.Width = 149, ;
		Lb_simplu1.Caption = "Valoare de repartizat", ;
		Lb_simplu1.Name = "Lb_simplu1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'cmdArticole' AS but_cautare WITH ;
		caction = do_cauta_articole, ;
		Left = 397, ;
		Name = "cmdArticole", ;
		TabIndex = 9, ;
		Top = 110, ;
		ZOrderSet = 10
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cmdFacturiTransport' AS but_cautare WITH ;
		caction = do_cauta_facturi_transport, ;
		Left = 396, ;
		Name = "cmdFacturiTransport", ;
		TabIndex = 8, ;
		Top = 48, ;
		ZOrderSet = 8
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'lb_explicatieTVA' AS label WITH ;
		AutoSize = .T., ;
		BackStyle = 0, ;
		Caption = "TVA", ;
		FontName = "Arial", ;
		Height = 17, ;
		Left = 439, ;
		Name = "lb_explicatieTVA", ;
		TabIndex = 11, ;
		Top = 48, ;
		Width = 23, ;
		ZOrderSet = 13
		*< END OBJECT: BaseClass="label" />
	
	PROCEDURE calculvaloarerepartizat
		lcXMLFacturi = this.cXmlfacturitransport 
		IF !EMPTY(lcXMLFacturi)
			XMLTOCURSOR(lcXMLFacturi, "crsFacturiTransport")
			lcNrFacturi = cursor2lista("crsFacturiTransport", "nract", ",")
			this.cListaIdFacturiTransport = cursor2lista("crsFacturiTransport","id_ireg_part",",")	
			SELECT crsFacturiTransport
			lnProcent = 100 + this.nProcentTVA
			CALCULATE SUM(ROUND(totctva*100/lnProcent,gnPC)) TO this.nTotalValoareRepartizat
			this.clb_facturi_transport.teXT_SIMPLU1.Value = lcNrFacturi
		
			USE IN crsFacturiTransport
		ELSE 
			this.clb_facturi_transport.teXT_SIMPLU1.Value = ""
			this.ntotalvaloarerepartizat = 0
		
		ENDIF 	
		this.clb_valoare_repartizat.text_simplu1.Refresh()
		this.clb_facturi_transport.text_SIMPLU1.Refresh()
		
	ENDPROC

	PROCEDURE do_cauta_articole
		LOCAL lcArticole, lcXMLArticole
		
		lcXMLArticole = caut_articol(0, .F., .T.)
			
		this.cXMLArticole = lcXMLArticole
		IF !EMPTY(lcXMLArticole)
		
			XMLTOCURSOR(lcXMLArticole, "crsArticole")
			lcArticole = cursor2lista("crsArticole", "denumire", ",")
			this.cListaIdArticole = cursor2lista("crsArticole","id_articol",",")
			
			USE IN crsArticole
			
			this.clb_articole.teXT_SIMPLU1.Value = lcArticole 
			this.clb_articole.text_SIMPLU1.Refresh()
		ENDIF 	
		
		
	ENDPROC

	PROCEDURE do_cauta_facturi_achizitie
	ENDPROC

	PROCEDURE do_cauta_facturi_transport
		LOCAL lcCont, lnIdPart, ldData1, ldData2, lcXMLFacturi
		
		lcCont = "401,408"
		ldData1 = DATE(gnAn, gnLuna, 1)
		ldData2 = GOMONTH(ldData1,2) - 1 && pot sa am factura de transport si in luna urmatoare
		
		IF this.nIdfurnizor <= 0
			aMESSAGEBOX("Alegeti furnizorul",0+48,"Atentie")
			RETURN
		ENDIF 
		
		lnIdPart = this.nIdfurnizor 
		lcXMLFacturi = caut_facturi(lcCont, lnIdPart, ldData1, ldData2)
		IF gnButon = 1
			this.cXmlfacturitransport = lcXMLFacturi
			this.calculvaloarerepartizat()
		ENDIF 	
	ENDPROC

	PROCEDURE do_cauta_furnizor
	ENDPROC

	PROCEDURE inainte_de_do_termin
		llSucces = .T.
		
		lcListaIdArticole = This.clistaidarticole
		lcListaIdFacturiTransport = This.cListaIdfacturitransport
		If Empty(lcListaIdArticole)
			llSucces = .F.
			AMESSAGEBOX('Alegeti articolele!', 0 + 48, 'Atentie')
		Endif
		
		If Empty(lcListaIdFacturiTransport)
			llSucces = .F.
			AMESSAGEBOX('Alegeti facturile de repartizat', 0 + 16, 'Facturi')
		Endif
		
		If llSucces
			If Type('oitem') = 'O'
				If Pemstatus(oitem,'adunadate',5)
					_Screen.MousePointer = 11
					*!*	modificare JC/JV 2007
					oitem.id_jnetax = Null
					oitem.id_jtax = Null
					oitem.id_jtva = Null
					*!*	modificare JC/JV 2007	^
					oitem.adunadate()
					_Screen.MousePointer = 0
				Endif
			Endif
		Endif
		
		If llSucces
			_Screen.MousePointer = 11
			llSucces = This.make_rul_temp()
			_Screen.MousePointer = 0
		Endif
		
		Return llSucces
		
	ENDPROC

	PROCEDURE Init
		DODEFAULT()
		
		IF USED('xcont')
			SELECT xcont
			LOCATE FOR cont_part = "401"
			IF FOUND()
				lcNumePart = ALLTRIM(numepart)
				lnIdPart = idpart
				this.nIdFurnizor = lnIdPart
				this.cNumeFurnizor = lcNumePart
			ENDIF 
		ENDIF 		
		
		
		
		
	ENDPROC

	PROCEDURE make_rul_temp
		LOCAL llSucces, lnSucces, lcListaIdArticole, lcListaIdFacturiTransport
		LOCAL lcSql, lcCursor, lnTotalValoareAchizitie, lnTotalValoareRepartizat, lnIdArticol, lnCant, lnCante, lnPret, lnIdGestiune
		LOCAL lcCont, lcAcont
		LOCAL lnCoeficient, lnValoareRepartizat, lnValoare, lnLuna, lnAn
		lcListaIdArticole = THIS.clistaidarticole
		lcListaIdFacturiTransport = THIS.cListaIdfacturitransport
		
		lnLuna = thisform.caut_anluna1.nluna
		lnAn = thisform.caut_anluna1.nan
		
		lcSql = [select v.*, v.id_gestiune as id_gestin, v.nume_gestiune as gestin, v.id_gestiune as id_gestout,] + ;
			[v.nume_gestiune as gestout, 0 as nuInConturiX from vrul v where 1=2]
		lcCursor = [rul_temp]
		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
		IF lnSucces < 0
			AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
		ENDIF
		
		
		IF lnSucces > 0
			lcselect = [SELECT A.DENUMIRE, A.CODMAT, G.NUME_GESTIUNE, S.id_articol, S.id_gestiune, S.pret, S.proc_tvav, S.cont, S.acont, S.cants, S.cant, S.cante, S.stoc FROM ] + ;
				[(select id_articol, id_gestiune, pret, proc_tvav, cont, acont, cants, cant, cante, (cants + cant - cante) as stoc from stoc where an = ] + ;
				TRANSFORM(m.lnAn) + [ and luna = ] + TRANSFORM(m.lnLuna) + [ and id_gestiune in (] + gcGestPermis + [)] + ;
				[ and (cants + cant - cante <> 0) and cant <> 0 and id_articol in (] + lcListaIdArticole + [)] + gcCondSucursala + ;
				[ order by id_articol) S LEFT JOIN NOM_ARTICOLE A ON S.ID_ARTICOL = A.ID_ARTICOL ] + ;
				[ LEFT JOIN NOM_GESTIUNI G ON S.ID_GESTIUNE = G.ID_GESTIUNE]
		
			*!*		lcSql = [select id_articol, id_gestiune, pret, proc_tvav, cont, acont, cants, cant, cante, (cants + cant - cante) as stoc from stoc where an = ] + ;
			*!*			TRANSFORM(gnAn) + [ and luna = ] + TRANSFORM(gnLuna) + [ and id_gestiune in (] + gcGestPermis + [)] + ;
			*!*			[ and (cants + cant - cante <> 0) and cant <> 0 and id_articol in (] + lcListaIdArticole + [)] + ;
			*!*			[ order by id_articol]
			*!*		lcCursor = [crsStoc]
			*!*		lnSucces = goExecutor.oExecute(lcSql,lcCursor)
			*!*		IF lnSucces < 0
			*!*			AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
			*!*		ENDIF
		
			loHash = GetHash()
			WITH loHash
				.SetValue("cSelect", lcselect)
				.SetValue("cColoana", "DENUMIRE, CODMAT, NUME_GESTIUNE, CONT, ACONT, PRET, STOC, ID_ARTICOL, ID_GESTIUNE")
				.SetValue("cTitlu", "Alegeti intrarile (Mouse Click sau SPATIU pe 'DENUMIRE')")
				.SetValue("cTitluColoana", "DENUMIRE, COD MATERIAL, NUME_GESTIUNE, CONT, ACONT, PRET, STOC, ID ARTICOL, ID GESTIUNE")
				.SetValue("cPrimaColoana", "denumire")
				.SetValue("nTipReturn", 1)
			ENDWITH
		
			TRY 
				lcXML = cauta_alfa_hash(loHash)	&&	11.07.2007
		
				IF !EMPTY(lcXML)
					XMLTOCURSOR(lcXML, "crsStoc")
				ELSE
					lnSucces = -1
				ENDIF		
			CATCH
				lnSucces = -1
			ENDTRY 		
		
		ENDIF
		
		*!*	modificare serii numere	-	10.2007
		*!*	IF lnSucces > 0
		*!*		&& PLAJE NIR-URI CMP
		*!*		lnTip = 4 && NIR PT CMP
		*!*		lnSerie = 2
		*!*		lnId_entitate = 0
		*!*		lnNnir1 = 0
		*!*		lnNnir2 = 0
		*!*		lcselect = [select id_plaja,pl_inf,pl_sup from ] + gcS + [.vplaje_numere where ] +;
		*!*			[inactiv = 0 and tip = ] + ALLTRIM(STR(lnTip)) + [ and serie = ] + ;
		*!*			ALLTRIM(STR(lnSerie)) + [ and id_entitate = ] + ALLTRIM(STR(lnId_entitate))
		*!*		lcCursor = [crsplaja]
		*!*		lnSucces = goExecutor.oExecute(lcselect,lcCursor)
		*!*		IF lnSucces < 0
		*!*			AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
		*!*		ELSE
		*!*			SELECT crsPlaja
		*!*			lnNnir1 = pl_inf
		*!*			lnNnir2 = pl_sup
		*!*		ENDIF
		*!*		USE IN crsPlaja
		*!*	ENDIF
		*!*	modificare serii numere	-	10.2007	^9
		
		IF lnSucces > 0
		*!*	modificare v 2.2.33 : am adaugat PRET
			SELECT DISTINCT ID_ARTICOL, ID_GESTIUNE, PADR(NVL(CONT,''), 4, ' ') AS CONT, PADR(NVL(ACONT,''), 4, ' ') AS ACONT, pret ;
				FROM crsStoc ;
				INTO CURSOR crsJoinTemp
		
		*!*	modificare serii numere	-	10.2007		
		*!*	modificare v 2.2.33 : pret, round(CANT*PRET,?gnPc)
			lcselect = [SELECT ID_ARTICOL, ID_GESTIUNE, CONT, ACONT, PRET, SUM(ROUND(CANT*PRET,?gnPc)) AS VALOARE FROM  RUL ] + ;
				[ WHERE STERS = 0  AND AN = ] + TRANSFORM(m.lnAn) + [ AND LUNA = ] + TRANSFORM(m.lnLuna) + ;
				[ and id_gestiune in (] + gcGestPermis + [)] + ;
				[ AND CANT <> 0 and id_tip_rulaj <> 2] + gcCondSucursala
		*!*		lcselect = [SELECT ID_ARTICOL, ID_GESTIUNE, CONT, ACONT, SUM(CANT*PRET) AS VALOARE FROM  RUL ] + ;
		*!*			[ WHERE STERS = 0  AND AN = ] + TRANSFORM(gnAn) + [ AND LUNA = ] + TRANSFORM(gnLuna) + [ and id_gestiune in (] + gcGestPermis + [)] + ;
		*!*			[ AND CANT <> 0 and (NNIR NOT BETWEEN ] + TRANSFORM(lnNnir1) + [ AND ] + TRANSFORM(lnNnir2) + [)]
		*!*		*!*			[ AND id_articol in (] + lcListaIdArticole + [)]
		*!*	modificare serii numere	-	10.2007 ^
			lcConditie = ""
			SELECT crsJoinTemp
			SCAN
				SCATTER NAME lorec
				lcConditie = lcConditie + [ OR (id_articol = ] + ALLTRIM(STR(lorec.ID_ARTICOL)) + [ and id_gestiune = ] + ALLTRIM(STR(lorec.ID_GESTIUNE)) + ;
					[ and cont = '] + ALLTRIM(lorec.CONT)  + IIF(!EMPTY(ALLTRIM(lorec.ACONT)), [' and acont = '] + ALLTRIM(lorec.ACONT) + ['], [']) + [)]
			ENDSCAN
			USE IN crsJoinTemp
			IF !EMPTY(lcConditie)
				lcConditie = SUBSTR(lcConditie, 5)
			ENDIF
			lcselect = lcselect + IIF(!EMPTY(lcConditie), [ AND (] + lcConditie + [)], [])
			*!*	modificare v 2.2.33 : am adaugat PRET
			lcselect = lcselect + [ GROUP BY ID_ARTICOL, ID_GESTIUNE, CONT, ACONT, PRET order by id_articol]
			lcCursor = [crsRulTemp]
			lnSucces = goExecutor.oExecute(lcselect,lcCursor)
			IF lnSucces < 0
				AMESSAGEBOX(goExecutor.cEroare,0+16, 'Eroare')
			ENDIF
		
		
		
			*!*		loHash = GetHash()
			*!*		WITH loHash
			*!*			.SetValue("cSelect", lcselect)
			*!*			.SetValue("cColoana", "DENUMIRE, CODMAT, NUME_GESTIUNE, CONT, ACONT, VALOARE, ID_ARTICOL, ID_GESTIUNE")
			*!*			.SetValue("cTitlu", "Alegeti intrarile")
			*!*			.SetValue("cTitluColoana", "DENUMIRE, COD MATERIAL, NUME_GESTIUNE, CONT, ACONT, VALOARE, ID ARTICOL, ID GESTIUNE")
			*!*			.SetValue("cPrimaColoana", "denumire")
			*!*			.SetValue("nTipReturn", 1)
			*!*		ENDWITH
		
			*!*		lcXML = cauta_alfa_hash(loHash)	&&	11.07.2007
		
			*!*		IF !EMPTY(lcXML)
			*!*			XMLTOCURSOR(lcXML, "crsRulTemp")
			*!*		ELSE
			*!*			lnSucces = -1
			*!*		ENDIF
		ENDIF
		
		IF lnSucces > 0
			SELECT crsRulTemp
			CALCULATE SUM(ROUND(valoare,gnPc)) TO lnTotalValoareAchizitie
			lnTotalValoareRepartizat = THIS.ntotalvaloarerepartizat
		
			LOCAL lnValoareRepartizatSuma
			lnValoareRepartizatSuma = 0
			
			SELECT crsStoc
			SCAN
				lnIdArticol = ID_ARTICOL
				lnCante = cants + cant - cante
				lnPret = PRET
				lnIdGestiune = ID_GESTIUNE
				lcCont = CONT
				lcAcont = ACONT
				lnStoc = stoc
		
				*!* SCOT STOCUL EXISTENT CU PRETUL VECHI
				SELECT rul_temp
				SCATTER NAME loRul BLANK
				WITH loRul
					.ID_ARTICOL = lnIdArticol
					.id_gestout = lnIdGestiune
					.ID_GESTIUNE = lnIdGestiune
					.cante = lnStoc
					.PRET = lnPret
					.CONT = lcCont
					.ACONT = lcAcont
				ENDWITH
		
				SELECT rul_temp
				APPEND BLANK
				GATHER NAME loRul
		
				*!* INTRODUC STOCUL EXISTENT CU PRETUL NOU
		
				*!*	coeficient_lesie = valoare_achizitie_lesie / valoare_achizitie_totala
				*!*	valoare_repartizata_lesie = valoare_totala_de_repartizat * coeficient_lesie
				*!*	valoare_lesie = valoare_stoc_lesie + valoare_repartizata_lesie
				*!*	pret_lesie = valoare_lesie / stoc_final_lesie
				SELECT crsRulTemp
		*!*	modificare v 2.2.33 : am adaugat PRET
				LOCATE FOR ID_ARTICOL = lnIdArticol AND ID_GESTIUNE = lnIdGestiune AND CONT = lcCont AND NVL(ACONT,'XXXX') = NVL(lcAcont,'XXXX') AND pret = lnPret
				IF FOUND()
					*!*	modificare v 2.2.33 : round(...)
					lnCoeficient = ROUND(valoare / lnTotalValoareAchizitie,2)
				ELSE
					lnCoeficient = 0
				ENDIF
		
				&& la ultimul reper valoarea de repartizat = total valoare de repartizat - valoarea repartizata pe reperele anterioare
				lnValoareRepartizat = ROUND(lnTotalValoareRepartizat * lnCoeficient, gnPc)
				IF RECCOUNT('crsStoc') = RECNO('crsStoc') && ultimul reper
					lnValoareRepartizat = lnTotalValoareRepartizat - lnValoareRepartizatSuma
				ELSE 	
					lnValoareRepartizatSuma = lnValoareRepartizatSuma + lnValoareRepartizat
				ENDIF 	
		
				lnValoare = ROUND(lnStoc * lnPret + lnValoareRepartizat, gnPc)
				lnPret = ROUND(lnValoare / lnStoc, gnPpret)
				SELECT rul_temp
				SCATTER NAME loRul BLANK
				WITH loRul
					.ID_ARTICOL = lnIdArticol
					.id_gestout = lnIdGestiune
					.ID_GESTIUNE = lnIdGestiune
					.cant = lnStoc
					.PRET = lnPret
					.CONT = lcCont
					.ACONT = lcAcont
				ENDWITH
		
				SELECT rul_temp
				APPEND BLANK
				GATHER NAME loRul
			ENDSCAN
		ENDIF
		
		SELECT rul_temp
		REPLACE ALL ID_TIP_RULAJ WITH 5 && RULAJ REPARTIZARE VALOARE PE ARTICOLE
		*!*	modificare	08.11.2007
		lcCont = cont	
		*!*	modificare	08.11.2007	^
		
		IF USED('ACTACTAN')
			SELECT ACTACTAN
			*!*	modificare JC/JV 2007
			REPLACE proc_tva WITH 0 FOR NVL(id_jtva_coloana,0)=0
			*!*	modificare JC/JV 2007	^
			GO TOP
		*!*	modificare	08.11.2007
			replace scd WITH lcCont
		*!*		REPLACE SCD WITH rul_temp.CONT
		*!*	modificare	08.11.2007	^
			SCATTER NAME loActactan
			SELECT rul_temp
			REPLACE ALL dataact WITH loActactan.dataact, ;
				nnir WITH loActactan.nnir, ;
				id_sectie WITH loActactan.id_sectie, ;
				id_responsabil WITH loActactan.id_responsabil, ;
				id_lucrare WITH loActactan.id_lucrare, nract WITH loActactan.nract, serie_act WITH loActactan.serie_act
		ENDIF
		
		IF USED('crsStoc')
			USE IN crsStoc
		ENDIF
		IF USED('crsRulTemp')
			USE IN crsRulTemp
		ENDIF
		
		llSucces = IIF(lnSucces > 0, .T., .F.)
		RETURN llSucces
		
	ENDPROC

	PROCEDURE cbo_explicatieTVA.Init
		Select jtva_coloane
		Locate For id_jtva_coloana = XSETS.id_jtax
		If ! Found()
			Go Top
		Endif
		Thisform.nProcenttva = cota_tva
		This.Value = Alltrim(denumire)
		
	ENDPROC

	PROCEDURE cbo_explicatieTVA.InteractiveChange
		Select jtva_coloane
		Thisform.nProcenttva = cota_tva
		Thisform.calculvaloarerepartizat()
	ENDPROC

ENDDEFINE
