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

	*<PropValue>
		DataSource = .NULL.
		Height = 0
		Left = 0
		Name = "Dataenvironment"
		Top = 0
		Width = 0
	*</PropValue>

ENDDEFINE

DEFINE CLASS frm_autopass1 AS _frmbase OF "..\comun\clase\_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="ShpBadgeMediu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblBadgeMediu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblPerioada1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtDataInceput1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblPerioadaLinie1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtDataSfarsit1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButActualizeaza1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblAcoperire1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButConfigurare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.LblUrl1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.TxtUrl1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.LblCheie1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.TxtCheie1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.ButAratacheie1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.LblMediu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.CboMediu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.ButTestConexiune1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.ButSalveazaConfig1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="PnlConfigurare1.LblConfigMesaj1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column1.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column1.Chk1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column2.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column2.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column3.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column3.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column4.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column4.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column5.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column5.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column6.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column6.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column7.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column7.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column8.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column8.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column9.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column9.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column10.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column10.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column11.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column11.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column12.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column12.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column13.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="GrdComenzi1.Column13.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblMotivTitlu1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="TxtMotivRand1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButSelecteazaTot1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButValideazaDryrun1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButTransmite1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButActualizeazaStatusuri1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButDeschideDashboard1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="ButRenuntaActiuni1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="LblProgres1" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: col_bifa_when		&& When() pe coloana de bifa a gridului - randurile invalide/netransmisibile nu se pot bifa (grid VFP nu are readonly per celula)
		*m: culoare_status		&& Culoarea (RGB) asociata unui status brut din gateway, pt DynamicForeColor in grid
		*m: do_actualizeaza_perioada		&& Reincarca cursoarele US-002 pentru perioada curenta din forma
		*m: do_actualizeaza_statusuri		&& Re-apeleaza autopass_situatie() + coreleaza si reimprospateaza gridul (US-005)
		*m: do_deschide_dashboard		&& Deschide in browser URL-ul gateway-ului din configurare
		*m: do_test_conexiune		&& GET /v1/ping - actualizeaza badge-ul de mediu si starea butoanelor
		*m: do_toggle_arata_cheie
		*m: do_toggle_configurare
		*m: do_transmite		&& POST /v1/prezentari in loturi de max nMaxLot, cu progres si Renunta intre loturi
		*m: do_valideaza_dryrun		&& POST /v1/prezentari/valideaza in loturi - completeaza doar coloana Verdict validare
		*m: eticheta_status		&& Traduce statusul brut din gateway (queued/sent/...) in eticheta romaneasca (vocabular US-004)
		*m: incarca_date		&& Construieste crs_autopass_comenzi + crs_autopass_operatii, aplica situatia gateway si reimprospateaza gridul
		*m: incarca_lot_din_grid		&& Construieste array de obiecte {vin,nrinmat,data_prestatie,odometru_final,prestatii[],obs,id_ordl} pt un lot de max nMaxLot randuri bifate
		*m: obtine_id_bifate		&& Array cu id_ordl ale randurilor bifate din crs_autopass_comenzi
		*m: recalculeaza_acoperire		&& Recalculeaza N/M/K si actualizeaza LblAcoperire1
		*m: salveaza_config
		*p: ccursordetaliu		&& Numele cursorului temporar cu operatiile (crs_autopass_operatii)
		*p: ccursorheader		&& Numele cursorului temporar cu comenzile (crs_autopass_comenzi)
		*p: ddatainceput
		*p: ddatasfarsit
		*p: lanulare		&& Setat de ButRenuntaActiuni1 in timpul unei transmiteri/dry-run in curs - verificat intre loturi
		*p: lconfigok
		*p: loperatieincurs		&& .T. cat timp o transmitere/dry-run e in desfasurare (guard dubla-apasare + tine ButRenuntaActiuni1 in modul "opreste")
		*p: lpingok
	*</DefinedPropArrayMethod>

	*<PropValue>
		AutoCenter = .T.
		Caption = "Trimitere operatii facturate la RAR AUTOPASS"
		ccursordetaliu = "crs_autopass_operatii"
		ccursorheader = "crs_autopass_comenzi"
		ddatainceput = {}
		ddatasfarsit = {}
		DoCreate = .T.
		Height = 700
		lanulare = .F.
		lconfigok = .F.
		loperatieincurs = .F.
		lpingok = .F.
		MaxButton = .F.
		MinButton = .F.
		Name = "Frm_autopass1"
		Width = 1020
		WindowType = 1
		_shape1.Width = 1017
		_shape2.Left = 962
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		BUT_TERMIN1.Left = 984
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.ToolTipText = "Inchide fereastra (ESC)"
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'ButActualizeaza1' AS _commandbutton WITH ;
		Caption = "Actualizeaza", ;
		Height = 24, ;
		Left = 332, ;
		Name = "ButActualizeaza1", ;
		Top = 60, ;
		Width = 96
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ButActualizeazaStatusuri1' AS _commandbutton WITH ;
		Anchor = 10, ;
		Caption = "Actualizeaza statusuri", ;
		Height = 28, ;
		Left = 664, ;
		Name = "ButActualizeazaStatusuri1", ;
		Top = 566, ;
		Width = 170
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ButConfigurare1' AS _commandbutton WITH ;
		Anchor = 9, ;
		Caption = "Configurare >>", ;
		Height = 24, ;
		Left = 904, ;
		Name = "ButConfigurare1", ;
		Top = 60, ;
		Width = 108
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ButDeschideDashboard1' AS _commandbutton WITH ;
		Anchor = 10, ;
		BackColor = 0,90,160, ;
		Caption = "Dashboard AutoPass", ;
		FontBold = .T., ;
		ForeColor = 255,255,255, ;
		Height = 28, ;
		Left = 851, ;
		Name = "ButDeschideDashboard1", ;
		Top = 566, ;
		Width = 150
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ButRenuntaActiuni1' AS _commandbutton WITH ;
		Anchor = 6, ;
		BackColor = 180,0,0, ;
		Caption = "Renunta", ;
		FontBold = .T., ;
		ForeColor = 255,255,255, ;
		Height = 28, ;
		Left = 494, ;
		Name = "ButRenuntaActiuni1", ;
		Top = 566, ;
		Visible = .F., ;
		Width = 140
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ButSelecteazaTot1' AS cmd_select_adv WITH ;
		Anchor = 6, ;
		ccoloana = "lbifat", ;
		cFiltruSuplimentar = "lvalid AND !INLIST(status_autopass,'queued','sent','deduped','held','needs_mapping','needs_data')", ;
		cgrid = "thisform.GrdComenzi1", ;
		Left = 8, ;
		Name = "ButSelecteazaTot1", ;
		Top = 566, ;
		Width = 160
		*< END OBJECT: ClassLib="..\comun\clase\cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ButTransmite1' AS _commandbutton WITH ;
		Anchor = 6, ;
		BackColor = 0,120,40, ;
		Caption = "Transmite", ;
		FontBold = .T., ;
		FontSize = 11, ;
		ForeColor = 255,255,255, ;
		Height = 30, ;
		Left = 348, ;
		Name = "ButTransmite1", ;
		Top = 565, ;
		Width = 140
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'ButValideazaDryrun1' AS _commandbutton WITH ;
		Anchor = 6, ;
		Caption = "Valideaza (dry-run)", ;
		Height = 28, ;
		Left = 188, ;
		Name = "ButValideazaDryrun1", ;
		Top = 566, ;
		Width = 150
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'GrdComenzi1' AS _grid WITH ;
		Anchor = 15, ;
		ColumnCount = 13, ;
		DeleteMark = .F., ;
		FontName = "Arial Narrow", ;
		Height = 370, ;
		lcamptextneeditabil = .T., ;
		Left = 8, ;
		Name = "GrdComenzi1", ;
		ReadOnly = .F., ;
		RecordSource = "", ;
		RowHeight = 18, ;
		Top = 118, ;
		Width = 1001, ;
		Column1.ColumnOrder = 1, ;
		Column1.ControlSource = "crs_autopass_comenzi.lbifat", ;
		Column1.CurrentControl = "Chk1", ;
		Column1.Name = "Column1", ;
		Column1.Sparse = .F., ;
		Column1.When = "Thisform.col_bifa_when()", ;
		Column1.Width = 30, ;
		Column2.ColumnOrder = 2, ;
		Column2.ControlSource = "crs_autopass_comenzi.nrord", ;
		Column2.Name = "Column2", ;
		Column2.Width = 60, ;
		Column3.ColumnOrder = 3, ;
		Column3.ControlSource = "crs_autopass_comenzi.dataoravalid", ;
		Column3.Name = "Column3", ;
		Column3.Width = 66, ;
		Column4.ColumnOrder = 4, ;
		Column4.ControlSource = "crs_autopass_comenzi.nrfact", ;
		Column4.Name = "Column4", ;
		Column4.Width = 60, ;
		Column5.ColumnOrder = 5, ;
		Column5.ControlSource = "crs_autopass_comenzi.datafact", ;
		Column5.Name = "Column5", ;
		Column5.Width = 66, ;
		Column6.ColumnOrder = 6, ;
		Column6.ControlSource = "crs_autopass_comenzi.nrinmat", ;
		Column6.Name = "Column6", ;
		Column6.Width = 74, ;
		Column7.ColumnOrder = 7, ;
		Column7.ControlSource = "crs_autopass_comenzi.series", ;
		Column7.Name = "Column7", ;
		Column7.Width = 130, ;
		Column8.ColumnOrder = 8, ;
		Column8.ControlSource = "crs_autopass_comenzi.kmint", ;
		Column8.Name = "Column8", ;
		Column8.Width = 55, ;
		Column9.ColumnOrder = 9, ;
		Column9.ControlSource = "crs_autopass_comenzi.nume", ;
		Column9.Name = "Column9", ;
		Column9.Width = 140, ;
		Column10.Alignment = 1, ;
		Column10.ColumnOrder = 10, ;
		Column10.ControlSource = "crs_autopass_comenzi.ncntop", ;
		Column10.Name = "Column10", ;
		Column10.Width = 40, ;
		Column11.ColumnOrder = 11, ;
		Column11.ControlSource = "crs_autopass_comenzi.cstatusro", ;
		Column11.DynamicForeColor = "Thisform.culoare_status(status_autopass)", ;
		Column11.FontBold = .T., ;
		Column11.Name = "Column11", ;
		Column11.Width = 140, ;
		Column12.ColumnOrder = 12, ;
		Column12.ControlSource = "crs_autopass_comenzi.cverdict", ;
		Column12.Name = "Column12", ;
		Column12.Width = 160, ;
		Column13.ColumnOrder = 13, ;
		Column13.ControlSource = "crs_autopass_comenzi.motiv_invalid", ;
		Column13.Name = "Column13", ;
		Column13.Width = 200
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="grid" />

	ADD OBJECT 'GrdComenzi1.Column1.Chk1' AS _checkbox WITH ;
		Alignment = 2, ;
		AutoSize = .F., ;
		Caption = "", ;
		ControlSource = "crs_autopass_comenzi.lbifat", ;
		Height = 16, ;
		Name = "Chk1", ;
		Width = 22
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="checkbox" />

	ADD OBJECT 'GrdComenzi1.Column1.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column10.Header1' AS header WITH ;
		Caption = "Op.", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column10.Text1' AS _textbox WITH ;
		Alignment = 1, ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column11.Header1' AS header WITH ;
		Caption = "Status transmitere", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column11.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		DynamicForeColor = "Thisform.culoare_status(status_autopass)", ;
		FontBold = .T., ;
		FontName = "Arial Narrow", ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column12.Header1' AS header WITH ;
		Caption = "Verdict validare", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column12.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 120,80,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column13.Header1' AS header WITH ;
		Caption = "Motiv (pre-validare)", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column13.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 160,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column2.Header1' AS header WITH ;
		Caption = "Nr.cmd", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column2.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column3.Header1' AS header WITH ;
		Caption = "Data inch.", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column3.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column4.Header1' AS header WITH ;
		Caption = "Nr.fact.", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column4.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column5.Header1' AS header WITH ;
		Caption = "Data fact.", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column5.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column6.Header1' AS header WITH ;
		Caption = "Nr.inmat.", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column6.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column7.Header1' AS header WITH ;
		Caption = "VIN", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column7.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column8.Header1' AS header WITH ;
		Caption = "Km", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column8.Text1' AS _textbox WITH ;
		Alignment = 1, ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'GrdComenzi1.Column9.Header1' AS header WITH ;
		Caption = "Client", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'GrdComenzi1.Column9.Text1' AS _textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		DynamicBackColor = "IIF(!lvalid,RGB(224,224,224),RGB(255,255,255))", ;
		FontName = "Arial Narrow", ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1", ;
		ReadOnly = .T.
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'LblAcoperire1' AS _label WITH ;
		Anchor = 13, ;
		AutoSize = .F., ;
		Caption = "Declarabile in perioada: - | Transmise: - | Blocate/nedeclarabile: -", ;
		FontBold = .T., ;
		Height = 18, ;
		Left = 8, ;
		Name = "LblAcoperire1", ;
		Top = 88, ;
		Width = 1001
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'LblBadgeMediu1' AS _label WITH ;
		Alignment = 2, ;
		Anchor = 13, ;
		AutoSize = .F., ;
		BackStyle = 0, ;
		Caption = "Se verifica mediul...", ;
		FontBold = .T., ;
		FontSize = 11, ;
		ForeColor = 255,255,255, ;
		Height = 20, ;
		Left = 8, ;
		Name = "LblBadgeMediu1", ;
		Top = 33, ;
		Width = 1001
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'LblMotivTitlu1' AS _label WITH ;
		Anchor = 6, ;
		Caption = "Motiv (rand curent):", ;
		Height = 18, ;
		Left = 8, ;
		Name = "LblMotivTitlu1", ;
		Top = 492, ;
		Width = 160
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'LblPerioada1' AS _label WITH ;
		AutoSize = .F., ;
		Caption = "Perioada (data facturii):", ;
		Height = 18, ;
		Left = 8, ;
		Name = "LblPerioada1", ;
		Top = 64, ;
		Width = 140
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'LblPerioadaLinie1' AS _label WITH ;
		Alignment = 2, ;
		Caption = "-", ;
		Height = 18, ;
		Left = 232, ;
		Name = "LblPerioadaLinie1", ;
		Top = 64, ;
		Width = 12
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'LblProgres1' AS _label WITH ;
		Anchor = 14, ;
		AutoSize = .F., ;
		Caption = "", ;
		Height = 18, ;
		Left = 8, ;
		Name = "LblProgres1", ;
		Top = 642, ;
		Width = 1001
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'PnlConfigurare1' AS _container WITH ;
		Anchor = 13, ;
		BackColor = 245,245,245, ;
		Height = 92, ;
		Left = 4, ;
		Name = "PnlConfigurare1", ;
		SpecialEffect = 1, ;
		Top = 112, ;
		Visible = .F., ;
		Width = 1009
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="container" />

	ADD OBJECT 'PnlConfigurare1.ButAratacheie1' AS _commandbutton WITH ;
		Anchor = 8, ;
		Caption = "Arata", ;
		Height = 22, ;
		Left = 945, ;
		Name = "ButAratacheie1", ;
		Top = 4, ;
		Width = 56
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'PnlConfigurare1.ButSalveazaConfig1' AS _commandbutton WITH ;
		Anchor = 8, ;
		Caption = "Salveaza", ;
		FontBold = .T., ;
		Height = 24, ;
		Left = 881, ;
		Name = "ButSalveazaConfig1", ;
		Top = 34, ;
		Width = 120
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'PnlConfigurare1.ButTestConexiune1' AS _commandbutton WITH ;
		Anchor = 8, ;
		Caption = "Test conexiune", ;
		Height = 24, ;
		Left = 721, ;
		Name = "ButTestConexiune1", ;
		Top = 34, ;
		Width = 150
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'PnlConfigurare1.CboMediu1' AS _combobox WITH ;
		Height = 24, ;
		Left = 100, ;
		Name = "CboMediu1", ;
		RowSource = "Testare,Productie,Implicit cont (gol)", ;
		RowSourceType = 1, ;
		Style = 2, ;
		Top = 34, ;
		Width = 160
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="combobox" />

	ADD OBJECT 'PnlConfigurare1.LblCheie1' AS _label WITH ;
		Caption = "Cheie API:", ;
		Height = 18, ;
		Left = 410, ;
		Name = "LblCheie1", ;
		Top = 8, ;
		Width = 78
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'PnlConfigurare1.LblConfigMesaj1' AS _label WITH ;
		Anchor = 12, ;
		AutoSize = .F., ;
		Caption = "", ;
		ForeColor = 180,0,0, ;
		Height = 18, ;
		Left = 8, ;
		Name = "LblConfigMesaj1", ;
		Top = 66, ;
		Width = 990
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'PnlConfigurare1.LblMediu1' AS _label WITH ;
		Caption = "Mediu RAR:", ;
		Height = 18, ;
		Left = 8, ;
		Name = "LblMediu1", ;
		Top = 38, ;
		Width = 90
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'PnlConfigurare1.LblUrl1' AS _label WITH ;
		Caption = "URL gateway:", ;
		Height = 18, ;
		Left = 8, ;
		Name = "LblUrl1", ;
		Top = 8, ;
		Width = 90
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="label" />

	ADD OBJECT 'PnlConfigurare1.TxtCheie1' AS _textbox WITH ;
		Height = 22, ;
		Left = 492, ;
		Name = "TxtCheie1", ;
		PasswordChar = "*", ;
		Top = 4, ;
		Width = 220
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'PnlConfigurare1.TxtUrl1' AS _textbox WITH ;
		Height = 22, ;
		Left = 100, ;
		Name = "TxtUrl1", ;
		Top = 4, ;
		Width = 300
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'ShpBadgeMediu1' AS _shape WITH ;
		Anchor = 13, ;
		BackColor = 160,160,160, ;
		Height = 26, ;
		Left = 0, ;
		Name = "ShpBadgeMediu1", ;
		Top = 30, ;
		Width = 1017
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="shape" />

	ADD OBJECT 'TxtDataInceput1' AS _textbox WITH ;
		ControlSource = "Thisform.ddatainceput", ;
		Format = "D", ;
		Height = 22, ;
		Left = 152, ;
		Name = "TxtDataInceput1", ;
		Top = 60, ;
		Width = 76
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'TxtDataSfarsit1' AS _textbox WITH ;
		ControlSource = "Thisform.ddatasfarsit", ;
		Format = "D", ;
		Height = 22, ;
		Left = 248, ;
		Name = "TxtDataSfarsit1", ;
		Top = 60, ;
		Width = 76
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="textbox" />

	ADD OBJECT 'TxtMotivRand1' AS _editbox WITH ;
		Anchor = 14, ;
		BackColor = 245,245,245, ;
		Height = 48, ;
		Left = 8, ;
		Name = "TxtMotivRand1", ;
		ReadOnly = .T., ;
		Top = 510, ;
		Width = 1001
		*< END OBJECT: ClassLib="..\comun\clase\_baza.vcx" BaseClass="editbox" />
	
	PROCEDURE col_bifa_when		&& When() pe coloana de bifa a gridului - randurile invalide/netransmisibile nu se pot bifa (grid VFP nu are readonly per celula)
		* Randurile fara operatii de manopera valide sau cu date invalide (VIN/nrinmat/data/km) nu
		* pot fi bifate - gridul VFP nu are readonly per celula, se foloseste When()=.F.
		RETURN crs_autopass_comenzi.lvalid
	ENDPROC

	PROCEDURE culoare_status		&& Culoarea (RGB) asociata unui status brut din gateway, pt DynamicForeColor in grid
		LPARAMETERS tcStatus
		LOCAL lcStatus
		lcStatus = LOWER(ALLTRIM(NVL(tcStatus,'')))
		DO CASE
		CASE lcStatus == 'sent'
			RETURN RGB(0,120,40)
		CASE lcStatus == 'queued'
			RETURN RGB(180,140,0)
		CASE INLIST(lcStatus,'needs_mapping','needs_data')
			RETURN RGB(200,110,0)
		CASE INLIST(lcStatus,'held','error')
			RETURN RGB(180,0,0)
		CASE lcStatus == 'deduped'
			RETURN RGB(120,120,120)
		OTHERWISE
			RETURN RGB(0,0,0)
		ENDCASE
	ENDPROC

	PROCEDURE do_actualizeaza_perioada		&& Reincarca cursoarele US-002 pentru perioada curenta din forma
		IF EMPTY(Thisform.ddatainceput) OR EMPTY(Thisform.ddatasfarsit) OR Thisform.ddatainceput > Thisform.ddatasfarsit
			MESSAGEBOX('Perioada introdusa este invalida.', 48, 'AUTOPASS')
			RETURN
		ENDIF
		Thisform.incarca_date()
	ENDPROC

	PROCEDURE do_actualizeaza_statusuri		&& Re-apeleaza autopass_situatie() + coreleaza si reimprospateaza gridul (US-005)
		LOCAL llOk
		llOk = autopass_situatie(Thisform.ddatainceput, Thisform.ddatasfarsit)
		IF USED(Thisform.ccursorheader)
			autopass_coreleaza_situatie(Thisform.ccursorheader)
			Thisform.GrdComenzi1.Refresh()
		ENDIF
		Thisform.recalculeaza_acoperire()
		IF !llOk
			Thisform.LblProgres1.Caption = 'Status necunoscut - situatia gateway indisponibila (vezi LOG.txt).'
			Thisform.LblProgres1.ForeColor = RGB(180,0,0)
		ELSE
			Thisform.LblProgres1.Caption = 'statusuri actualizate'
			Thisform.LblProgres1.ForeColor = RGB(0,100,0)
		ENDIF
	ENDPROC

	PROCEDURE do_deschide_dashboard		&& Deschide in browser URL-ul gateway-ului din configurare
		LOCAL loConfig, lcUrl
		DECLARE INTEGER ShellExecute IN shell32.dll ;
			INTEGER hndWin, STRING cAction, STRING cFileName, ;
			STRING cParameters, STRING cDirectory, INTEGER nShowWindow
		loConfig = autopass_get_config()
		lcUrl = ALLTRIM(loConfig.cUrlGateway)
		IF EMPTY(lcUrl)
			RETURN
		ENDIF
		ShellExecute(0, "Open", lcUrl, "", "", 1)
	ENDPROC

	PROCEDURE do_test_conexiune		&& GET /v1/ping - actualizeaza badge-ul de mediu si starea butoanelor
		LOCAL loRez
		WAIT WINDOW 'Se verifica conexiunea la gateway-ul AUTOPASS...' NOWAIT
		loRez = autopass_test_conexiune(ALLTRIM(Thisform.PnlConfigurare1.TxtUrl1.Value), ;
			ALLTRIM(Thisform.PnlConfigurare1.TxtCheie1.Value))
		WAIT CLEAR
		Thisform.lpingok = loRez.lSucces
		IF loRez.lSucces
			Thisform.cMediuActual = loRez.cMediu
			IF UPPER(ALLTRIM(loRez.cMediu)) == 'PROD' OR UPPER(ALLTRIM(loRez.cMediu)) == 'PRODUCTIE'
				Thisform.ShpBadgeMediu1.BackColor = RGB(180,0,0)
				Thisform.LblBadgeMediu1.Caption = 'MEDIU: PRODUCTIE - autentificat cu cheie: ' + IIF(loRez.lAutentificatCuCheie,'DA','NU')
			ELSE
				Thisform.ShpBadgeMediu1.BackColor = RGB(120,120,120)
				Thisform.LblBadgeMediu1.Caption = 'MEDIU: TESTARE - autentificat cu cheie: ' + IIF(loRez.lAutentificatCuCheie,'DA','NU')
			ENDIF
			Thisform.PnlConfigurare1.LblConfigMesaj1.Caption = ''
			Thisform.ButTransmite1.Enabled = .T.
			Thisform.ButValideazaDryrun1.Enabled = .T.
		ELSE
			Thisform.ShpBadgeMediu1.BackColor = RGB(160,160,160)
			Thisform.LblBadgeMediu1.Caption = 'Conexiune indisponibila'
			Thisform.PnlConfigurare1.LblConfigMesaj1.Caption = loRez.cEroare
			Thisform.ButTransmite1.Enabled = .F.
			Thisform.ButValideazaDryrun1.Enabled = .F.
			IF !Thisform.PnlConfigurare1.Visible
				Thisform.do_toggle_configurare()
			ENDIF
			Thisform.PnlConfigurare1.TxtCheie1.SetFocus()
		ENDIF
	ENDPROC

	PROCEDURE do_toggle_arata_cheie
		IF Thisform.PnlConfigurare1.TxtCheie1.PasswordChar == '*'
			Thisform.PnlConfigurare1.TxtCheie1.PasswordChar = ''
			Thisform.PnlConfigurare1.ButAratacheie1.Caption = 'Ascunde'
		ELSE
			Thisform.PnlConfigurare1.TxtCheie1.PasswordChar = '*'
			Thisform.PnlConfigurare1.ButAratacheie1.Caption = 'Arata'
		ENDIF
	ENDPROC

	PROCEDURE do_toggle_configurare
		Thisform.PnlConfigurare1.Visible = !Thisform.PnlConfigurare1.Visible
		IF Thisform.PnlConfigurare1.Visible
			Thisform.ButConfigurare1.Caption = 'Configurare <<'
			Thisform.GrdComenzi1.Top = 210
			Thisform.GrdComenzi1.Height = 278
		ELSE
			Thisform.ButConfigurare1.Caption = 'Configurare >>'
			Thisform.GrdComenzi1.Top = 118
			Thisform.GrdComenzi1.Height = 370
		ENDIF
	ENDPROC

	PROCEDURE do_transmite		&& POST /v1/prezentari in loturi de max nMaxLot, cu progres si Renunta intre loturi
		* Transmitere reala (enqueue) in loturi de max oClient.nMaxLot. Sincron (WinHTTP) - se
		* verifica Thisform.lanulare intre loturi (singurul punct de anulare posibil), cu
		* DOEVENTS ca sa lase interfata sa raspunda la clicul pe Renunta.
		LOCAL laIdBifate(1), lnTotal, oClient, lnLoturi, i, lnStart, lnEnd, laLot(1), j
		LOCAL loRez, loItem, lcMediuConfirm, lnRasp, lnTransmise, lnAsteptare, lnErori
		
		IF Thisform.loperatieincurs
			RETURN
		ENDIF
		
		lnTotal = Thisform.obtine_id_bifate(@laIdBifate)
		IF lnTotal = 0
			MESSAGEBOX('Nu exista nicio comanda bifata.', 48, 'AUTOPASS')
			RETURN
		ENDIF
		
		lcMediuConfirm = IIF(UPPER(ALLTRIM(Thisform.cMediuActual)) == 'PROD' OR UPPER(ALLTRIM(Thisform.cMediuActual)) == 'PRODUCTIE', 'PRODUCTIE', 'TESTARE')
		
		lnRasp = MESSAGEBOX('Se transmit ' + TRANSFORM(lnTotal) + ' comenzi in mediul ' + lcMediuConfirm + '.' + CHR(13) + ;
			IIF(lcMediuConfirm == 'PRODUCTIE', 'ATENTIE: declararea la RAR pe PRODUCTIE este ireversibila.' + CHR(13), '') + ;
			'Continuati?', 4 + 48 + 256, 'Confirmare transmitere AUTOPASS')
		IF lnRasp <> 6
			RETURN
		ENDIF
		
		IF lnTotal > 200
			lnRasp = MESSAGEBOX('Ati bifat ' + TRANSFORM(lnTotal) + ' comenzi (peste pragul de 200).' + CHR(13) + ;
				'Confirmati din nou transmiterea?', 4 + 48 + 256, 'Confirmare suplimentara AUTOPASS')
			IF lnRasp <> 6
				RETURN
			ENDIF
		ENDIF
		
		Thisform.loperatieincurs = .T.
		Thisform.lanulare = .F.
		Thisform.ButTransmite1.Enabled = .F.
		Thisform.ButValideazaDryrun1.Enabled = .F.
		Thisform.ButRenuntaActiuni1.Caption = '\<Opreste transmiterea'
		Thisform.ButRenuntaActiuni1.Visible = .T.
		
		oClient = CREATEOBJECT('AutopassClient')
		lnLoturi = CEILING(lnTotal / oClient.nMaxLot)
		lnTransmise = 0
		lnAsteptare = 0
		lnErori = 0
		
		FOR i = 1 TO lnLoturi
			IF Thisform.lanulare
				EXIT
			ENDIF
		
			lnStart = (i - 1) * oClient.nMaxLot + 1
			lnEnd = MIN(i * oClient.nMaxLot, lnTotal)
		
			Thisform.LblProgres1.Caption = 'Se transmite lotul ' + TRANSFORM(i) + '/' + TRANSFORM(lnLoturi) + '...'
			Thisform.LblProgres1.Refresh()
			DOEVENTS
		
			DIMENSION laLot(lnEnd - lnStart + 1)
			FOR j = lnStart TO lnEnd
				laLot(j - lnStart + 1) = laIdBifate(j)
			ENDFOR
		
			loRez = oClient.TrimiteLot(Thisform.incarca_lot_din_grid(@laLot))
		
			IF loRez.lSucces
				FOR EACH loItem IN loRez.oRezultate
					SELECT (Thisform.ccursorheader)
					LOCATE FOR id_ordl = loItem.id_ordl
					IF FOUND()
						REPLACE status_autopass WITH loItem.status, ;
							motiv_autopass WITH loItem.motiv, ;
							id_prezentare_autopass WITH loItem.id_prezentare, ;
							cstatusro WITH Thisform.eticheta_status(loItem.status), ;
							lbifat WITH .F.
						DO CASE
						CASE loItem.status == 'sent'
							lnTransmise = lnTransmise + 1
						CASE INLIST(loItem.status,'needs_mapping','needs_data','held','error')
							lnErori = lnErori + 1
						OTHERWISE
							lnAsteptare = lnAsteptare + 1
						ENDCASE
					ENDIF
				ENDFOR
			ELSE
				MESSAGEBOX('Lotul ' + TRANSFORM(i) + ' a esuat: ' + loRez.cDetaliu, 48, 'AUTOPASS')
				lnErori = lnErori + (lnEnd - lnStart + 1)
			ENDIF
		
			Thisform.GrdComenzi1.Refresh()
			DOEVENTS
		ENDFOR
		
		Thisform.loperatieincurs = .F.
		Thisform.ButRenuntaActiuni1.Visible = .F.
		Thisform.ButRenuntaActiuni1.Caption = 'Renunta'
		Thisform.ButTransmite1.Enabled = Thisform.lpingok
		Thisform.ButValideazaDryrun1.Enabled = Thisform.lpingok
		
		Thisform.recalculeaza_acoperire()
		
		Thisform.LblProgres1.Caption = TRANSFORM(lnTransmise) + ' transmise, ' + TRANSFORM(lnAsteptare) + ' in asteptare, ' + TRANSFORM(lnErori) + ' cu eroare/nemapate.'
		MESSAGEBOX(Thisform.LblProgres1.Caption + IIF(Thisform.lanulare, CHR(13) + '(transmitere intrerupta de utilizator)', ''), 64, 'AUTOPASS - sumar transmitere')
	ENDPROC

	PROCEDURE do_valideaza_dryrun		&& POST /v1/prezentari/valideaza in loturi - completeaza doar coloana Verdict validare
		* Dry-run: /v1/prezentari/valideaza pe selectie - NU face enqueue, completeaza doar
		* coloana separata "Verdict validare" (nu suprascrie status_autopass).
		LOCAL laIdBifate(1), lnTotal, oClient, lnLoturi, i, lnStart, lnEnd, laLot(1), j
		LOCAL loRez, loItem, lcVerdict, lnOk, lnNemapate
		
		IF Thisform.loperatieincurs
			RETURN
		ENDIF
		
		lnTotal = Thisform.obtine_id_bifate(@laIdBifate)
		IF lnTotal = 0
			MESSAGEBOX('Nu exista nicio comanda bifata.', 48, 'AUTOPASS')
			RETURN
		ENDIF
		
		Thisform.loperatieincurs = .T.
		Thisform.lanulare = .F.
		Thisform.ButTransmite1.Enabled = .F.
		Thisform.ButValideazaDryrun1.Enabled = .F.
		Thisform.ButRenuntaActiuni1.Caption = '\<Opreste transmiterea'
		Thisform.ButRenuntaActiuni1.Visible = .T.
		
		oClient = CREATEOBJECT('AutopassClient')
		lnLoturi = CEILING(lnTotal / oClient.nMaxLot)
		lnOk = 0
		lnNemapate = 0
		
		FOR i = 1 TO lnLoturi
			IF Thisform.lanulare
				EXIT
			ENDIF
		
			lnStart = (i - 1) * oClient.nMaxLot + 1
			lnEnd = MIN(i * oClient.nMaxLot, lnTotal)
		
			Thisform.LblProgres1.Caption = 'Validare (dry-run) lot ' + TRANSFORM(i) + '/' + TRANSFORM(lnLoturi) + '...'
			Thisform.LblProgres1.Refresh()
			DOEVENTS
		
			DIMENSION laLot(lnEnd - lnStart + 1)
			FOR j = lnStart TO lnEnd
				laLot(j - lnStart + 1) = laIdBifate(j)
			ENDFOR
		
			loRez = oClient.Valideaza(Thisform.incarca_lot_din_grid(@laLot))
		
			IF loRez.lSucces
				FOR EACH loItem IN loRez.oRezultate
					lcVerdict = Thisform.eticheta_status(loItem.status_estimat)
					IF !EMPTY(loItem.coduri_nemapate)
						lcVerdict = lcVerdict + ' (coduri nemapate: ' + TRANSFORM(loItem.coduri_nemapate) + ')'
						lnNemapate = lnNemapate + 1
					ELSE
						lnOk = lnOk + 1
					ENDIF
					SELECT (Thisform.ccursorheader)
					LOCATE FOR id_ordl = loItem.id_ordl
					IF FOUND()
						REPLACE cverdict WITH lcVerdict
					ENDIF
				ENDFOR
			ELSE
				MESSAGEBOX('Validarea lotului ' + TRANSFORM(i) + ' a esuat: ' + loRez.cDetaliu, 48, 'AUTOPASS')
			ENDIF
		
			Thisform.GrdComenzi1.Refresh()
			DOEVENTS
		ENDFOR
		
		Thisform.loperatieincurs = .F.
		Thisform.ButRenuntaActiuni1.Visible = .F.
		Thisform.ButRenuntaActiuni1.Caption = 'Renunta'
		Thisform.ButTransmite1.Enabled = Thisform.lpingok
		Thisform.ButValideazaDryrun1.Enabled = Thisform.lpingok
		
		Thisform.LblProgres1.Caption = 'Validare: ' + TRANSFORM(lnOk) + ' OK, ' + TRANSFORM(lnNemapate) + ' coduri nemapate.'
	ENDPROC

	PROCEDURE eticheta_status		&& Traduce statusul brut din gateway (queued/sent/...) in eticheta romaneasca (vocabular US-004)
		* Vocabular statusuri gateway -> eticheta romaneasca (US-004) - NU se afiseaza tokenii
		* englezesti bruti in grid.
		LPARAMETERS tcStatus
		LOCAL lcStatus
		lcStatus = LOWER(ALLTRIM(NVL(tcStatus,'')))
		DO CASE
		CASE EMPTY(lcStatus)
			RETURN 'Netransmis'
		CASE lcStatus == 'queued'
			RETURN 'In asteptare la RAR'
		CASE lcStatus == 'sent'
			RETURN 'Transmis'
		CASE lcStatus == 'needs_mapping'
			RETURN 'Cod fara mapare RAR'
		CASE lcStatus == 'needs_data'
			RETURN 'Date incomplete'
		CASE lcStatus == 'held'
			RETURN 'Retinut (Auto OFF)'
		CASE lcStatus == 'error'
			RETURN 'Eroare'
		CASE lcStatus == 'deduped'
			RETURN 'Deja transmis'
		OTHERWISE
			RETURN ALLTRIM(tcStatus)
		ENDCASE
	ENDPROC

	PROCEDURE incarca_date		&& Construieste crs_autopass_comenzi + crs_autopass_operatii, aplica situatia gateway si reimprospateaza gridul
		* US-002 + US-005: extrage comenzile+operatiile facturate din perioada, aplica
		* pre-validarea locala (deja facuta in autopass_cursor_comenzi/operatii), calculeaza
		* nr. de operatii per comanda si coreleaza cu situatia gateway-ului.
		LOCAL lcHeader, lcDetaliu, lcCount
		
		WAIT WINDOW 'Se incarca comenzile facturate din perioada...' NOWAIT
		
		lcHeader = autopass_cursor_comenzi(Thisform.ddatainceput, Thisform.ddatasfarsit)
		IF EMPTY(lcHeader)
			WAIT CLEAR
			MESSAGEBOX('Nu s-au putut extrage comenzile pentru perioada aleasa (vezi LOG.txt).', 48, 'AUTOPASS')
			RETURN
		ENDIF
		
		lcDetaliu = autopass_cursor_operatii(lcHeader)
		
		*-- lbifat/ncntop/cstatusro/cverdict sunt incluse direct la crearea cursorului in
		*-- autopass_cursor_comenzi() - cursorul ramane "remote"-tainted, ALTER TABLE pica.
		
		IF !EMPTY(lcDetaliu) AND USED(lcDetaliu)
			lcCount = 'crs_autopass_nrop'
			IF USED(lcCount)
				USE IN (lcCount)
			ENDIF
			SELECT id_ordl, COUNT(*) AS ncnt FROM (lcDetaliu) WHERE lvalid_op GROUP BY id_ordl INTO CURSOR (lcCount) READWRITE
			INDEX ON id_ordl TAG id_ordl
			SET ORDER TO id_ordl IN (lcCount)
		
			SELECT (lcHeader)
			SCAN
				IF SEEK(id_ordl, lcCount)
					REPLACE ncntop WITH &lcCount..ncnt
				ELSE
					REPLACE ncntop WITH 0
				ENDIF
			ENDSCAN
			USE IN (lcCount)
		ENDIF
		
		SELECT (lcHeader)
		REPLACE ALL lbifat WITH .F., cstatusro WITH 'Netransmis', cverdict WITH ''
		GO TOP
		
		WAIT CLEAR
		
		*-- situatia gateway-ului (US-005), auto-refresh la incarcarea perioadei
		LOCAL lcEroareSituatie
		lcEroareSituatie = ''
		IF autopass_situatie(Thisform.ddatainceput, Thisform.ddatasfarsit, @lcEroareSituatie)
			autopass_coreleaza_situatie(lcHeader)
			SELECT (lcHeader)
			SCAN
				REPLACE cstatusro WITH Thisform.eticheta_status(status_autopass)
			ENDSCAN
			SELECT (lcHeader)
			GO TOP
		ELSE
			Thisform.LblProgres1.Caption = 'Situatia gateway indisponibila: ' + ;
				IIF(EMPTY(lcEroareSituatie), 'motiv necunoscut (vezi LOG.txt).', lcEroareSituatie)
			Thisform.LblProgres1.ForeColor = RGB(180,0,0)
		ENDIF
		
		Thisform.GrdComenzi1.RecordSource = lcHeader
		Thisform.GrdComenzi1.Refresh()
		Thisform.ButSelecteazaTot1.Setup()
		Thisform.ButSelecteazaTot1.nselectate = 0
		Thisform.ButSelecteazaTot1.schimba_caption()
		
		IF RECCOUNT(lcHeader) = 0
			Thisform.LblProgres1.Caption = 'Nu exista comenzi facturate in perioada aleasa.'
			Thisform.ButTransmite1.Enabled = .F.
			Thisform.ButValideazaDryrun1.Enabled = .F.
		ELSE
			Thisform.ButTransmite1.Enabled = Thisform.lpingok
			Thisform.ButValideazaDryrun1.Enabled = Thisform.lpingok
		ENDIF
		
		Thisform.recalculeaza_acoperire()
	ENDPROC

	PROCEDURE incarca_lot_din_grid		&& Construieste array de obiecte {vin,nrinmat,data_prestatie,odometru_final,prestatii[],obs,id_ordl} pt un lot de max nMaxLot randuri bifate
		* Construieste array de obiecte {vin,nrinmat,data_prestatie,odometru_final,prestatii[],obs,id_ordl}
		* pentru AutopassClient.TrimiteLot()/Valideaza(), pe baza id_ordl-urilor primite (un lot,
		* max nMaxLot elemente - impartirea pe loturi e responsabilitatea formei).
		LPARAMETERS taIdLot
		LOCAL lnCount, i, loComanda, lcDataPrest, laPrestatii(1), lnNrOp
		LOCAL ARRAY laLot(1)
		
		lnCount = ALEN(taIdLot,1)
		DIMENSION laLot(lnCount)
		
		FOR i = 1 TO lnCount
			SELECT (Thisform.ccursorheader)
			LOCATE FOR id_ordl = taIdLot(i)
		
			loComanda = CREATEOBJECT('empty')
			ADDPROPERTY(loComanda, 'id_ordl', id_ordl)
			ADDPROPERTY(loComanda, 'vin', ALLTRIM(series))
			ADDPROPERTY(loComanda, 'nrinmat', ALLTRIM(nrinmat))
		
			DO CASE
			CASE VARTYPE(dataoravalid) = 'T'
				lcDataPrest = STR(YEAR(TTOD(dataoravalid)),4) + '-' + PADL(MONTH(TTOD(dataoravalid)),2,'0') + '-' + PADL(DAY(TTOD(dataoravalid)),2,'0')
			CASE VARTYPE(dataoravalid) = 'D'
				lcDataPrest = STR(YEAR(dataoravalid),4) + '-' + PADL(MONTH(dataoravalid),2,'0') + '-' + PADL(DAY(dataoravalid),2,'0')
			OTHERWISE
				lcDataPrest = ''
			ENDCASE
			ADDPROPERTY(loComanda, 'data_prestatie', lcDataPrest)
			ADDPROPERTY(loComanda, 'odometru_final', kmint)
			ADDPROPERTY(loComanda, 'obs', autopass_obs(nrord, nrfact))
		
			lnNrOp = 0
			IF USED(Thisform.ccursordetaliu)
				SELECT (Thisform.ccursordetaliu)
				SCAN FOR id_ordl = taIdLot(i) AND lvalid_op
					lnNrOp = lnNrOp + 1
					DIMENSION laPrestatii(lnNrOp)
					laPrestatii(lnNrOp) = CREATEOBJECT('empty')
					ADDPROPERTY(laPrestatii(lnNrOp), 'cod_op_service', ALLTRIM(codop))
					ADDPROPERTY(laPrestatii(lnNrOp), 'denumire', ALLTRIM(denop))
				ENDSCAN
			ENDIF
			IF lnNrOp = 0
				DIMENSION laPrestatii(1)
			ENDIF
			loComanda.AddProperty('prestatii')
			loComanda.prestatii = laPrestatii
		
			laLot(i) = loComanda
		ENDFOR
		
		RETURN laLot
	ENDPROC

	PROCEDURE Init
		LOCAL loConfig
		
		DODEFAULT()
		
		This.WindowState = 2
		
		Thisform.ddatainceput = GOMONTH(DATE(), -1*(DAY(DATE())-1))
		Thisform.ddatasfarsit = DATE()
		
		Thisform.AddProperty('cMediuActual', '')
		
		loConfig = autopass_get_config()
		Thisform.PnlConfigurare1.TxtUrl1.Value = loConfig.cUrlGateway
		Thisform.PnlConfigurare1.TxtCheie1.Value = loConfig.cApiKey
		DO CASE
		CASE LOWER(ALLTRIM(loConfig.cRarEnv)) == 'test'
			Thisform.PnlConfigurare1.CboMediu1.Value = 'Testare'
		CASE LOWER(ALLTRIM(loConfig.cRarEnv)) == 'prod'
			Thisform.PnlConfigurare1.CboMediu1.Value = 'Productie'
		OTHERWISE
			Thisform.PnlConfigurare1.CboMediu1.Value = 'Implicit cont (gol)'
		ENDCASE
		
		Thisform.lconfigok = loConfig.lconfigok
		IF !Thisform.lconfigok
			Thisform.do_toggle_configurare()
			Thisform.PnlConfigurare1.LblConfigMesaj1.Caption = 'Completeaza cheia API (si URL-ul, daca e nevoie) si apasa Salveaza.'
		ENDIF
		
		*-- fail-closed pana raspunde ping-ul (US-004)
		Thisform.ButTransmite1.Enabled = .F.
		Thisform.ButValideazaDryrun1.Enabled = .F.
		
		Thisform.do_test_conexiune()
		
		Thisform.incarca_date()
	ENDPROC

	PROCEDURE Load
		* Precreeaza crs_autopass_comenzi INAINTE ca GrdComenzi1 sa fie instantiat (Load
		* ruleaza inaintea obiectelor continute) - altfel coloanele cu ControlSource
		* alias-calificat arunca "Alias not found" la deschiderea formei (Column1 are
		* Sparse=.F., care forteaza rezolvarea eager a alias-ului la creare).
		LOCAL lcHeader
		
		Thisform.ddatainceput = GOMONTH(DATE(), -1*(DAY(DATE())-1))
		Thisform.ddatasfarsit = DATE()
		
		lcHeader = autopass_cursor_comenzi(Thisform.ddatainceput, Thisform.ddatasfarsit)
		IF !EMPTY(lcHeader)
			autopass_cursor_operatii(lcHeader)
			*-- lbifat/ncntop/cstatusro/cverdict sunt incluse direct la crearea cursorului in
			*-- autopass_cursor_comenzi() - cursorul ramane "remote"-tainted, ALTER TABLE pica.
		ENDIF
	ENDPROC

	PROCEDURE obtine_id_bifate		&& Array cu id_ordl ale randurilor bifate din crs_autopass_comenzi
		LPARAMETERS taId
		LOCAL lnCount
		
		lnCount = 0
		IF USED(Thisform.ccursorheader)
			SELECT (Thisform.ccursorheader)
			SCAN FOR lbifat
				lnCount = lnCount + 1
				DIMENSION taId(lnCount)
				taId(lnCount) = id_ordl
			ENDSCAN
		ENDIF
		
		RETURN lnCount
	ENDPROC

	PROCEDURE recalculeaza_acoperire		&& Recalculeaza N/M/K si actualizeaza LblAcoperire1
		* "Declarabile in perioada: N | Transmise (sent): M | Blocate/nedeclarabile: K" -
		* singura metrica ce raspunde la "suntem conformi?" (US-004).
		LOCAL lnDeclarabile, lnTransmise, lnBlocate
		
		lnDeclarabile = 0
		lnTransmise = 0
		lnBlocate = 0
		
		IF USED(Thisform.ccursorheader)
			SELECT (Thisform.ccursorheader)
			COUNT FOR lvalid TO lnDeclarabile
			COUNT FOR status_autopass == 'sent' TO lnTransmise
			COUNT FOR !lvalid OR INLIST(status_autopass,'error','held','needs_mapping','needs_data') TO lnBlocate
		ENDIF
		
		Thisform.LblAcoperire1.Caption = 'Declarabile in perioada: ' + TRANSFORM(lnDeclarabile) + ;
			' | Transmise: ' + TRANSFORM(lnTransmise) + ;
			' | Blocate/nedeclarabile: ' + TRANSFORM(lnBlocate)
		Thisform.LblAcoperire1.ForeColor = IIF(lnBlocate > 0, RGB(180,0,0), RGB(0,0,0))
	ENDPROC

	PROCEDURE salveaza_config
		LOCAL lcEnv, llOk
		
		DO CASE
		CASE Thisform.PnlConfigurare1.CboMediu1.Value == 'Testare'
			lcEnv = 'test'
		CASE Thisform.PnlConfigurare1.CboMediu1.Value == 'Productie'
			lcEnv = 'prod'
		OTHERWISE
			lcEnv = ''
		ENDCASE
		
		llOk = autopass_salveaza_config(ALLTRIM(Thisform.PnlConfigurare1.TxtUrl1.Value), ;
			ALLTRIM(Thisform.PnlConfigurare1.TxtCheie1.Value), lcEnv)
		
		IF !llOk
			MESSAGEBOX('Salvarea configurarii AUTOPASS a esuat.', 48, 'AUTOPASS')
			RETURN
		ENDIF
		
		*-- config-ul se reciteste, ping-ul se reia automat, badge-ul si starea butoanelor
		*-- se actualizeaza fara a inchide fereastra
		Thisform.do_test_conexiune()
		IF Thisform.lpingok
			Thisform.do_actualizeaza_statusuri()
		ENDIF
	ENDPROC

	PROCEDURE ButActualizeaza1.Click
		Thisform.do_actualizeaza_perioada()
	ENDPROC

	PROCEDURE ButActualizeazaStatusuri1.Click
		Thisform.do_actualizeaza_statusuri()
	ENDPROC

	PROCEDURE ButConfigurare1.Click
		Thisform.do_toggle_configurare()
	ENDPROC

	PROCEDURE ButDeschideDashboard1.Click
		Thisform.do_deschide_dashboard()
	ENDPROC

	PROCEDURE ButRenuntaActiuni1.Click
		* In timpul unei transmiteri/dry-run: opreste dupa lotul curent. Altfel: inchide fereastra
		* (acelasi comportament ca BUT_TERMIN1 din titlu, mostenit din _frmbase).
		IF Thisform.loperatieincurs
			Thisform.lanulare = .T.
		ELSE
			Thisform.do_termin()
		ENDIF
	ENDPROC

	PROCEDURE ButTransmite1.Click
		Thisform.do_transmite()
	ENDPROC

	PROCEDURE ButValideazaDryrun1.Click
		Thisform.do_valideaza_dryrun()
	ENDPROC

	PROCEDURE GrdComenzi1.AfterRowColChange
		LPARAMETERS nColIndex
		IF USED(Thisform.ccursorheader) AND RECCOUNT(Thisform.ccursorheader) > 0
			SELECT (Thisform.ccursorheader)
			Thisform.TxtMotivRand1.Value = ALLTRIM(motiv_invalid) + ;
				IIF(!EMPTY(motiv_autopass), IIF(!EMPTY(motiv_invalid),' | ','') + ALLTRIM(motiv_autopass), '')
		ENDIF
	ENDPROC

	PROCEDURE PnlConfigurare1.ButAratacheie1.Click
		Thisform.do_toggle_arata_cheie()
	ENDPROC

	PROCEDURE PnlConfigurare1.ButSalveazaConfig1.Click
		Thisform.salveaza_config()
	ENDPROC

	PROCEDURE PnlConfigurare1.ButTestConexiune1.Click
		Thisform.do_test_conexiune()
	ENDPROC

ENDDEFINE
