forward
global type w_aabs_report_parameters_single from w_response
end type
type st_4 from statictext within w_aabs_report_parameters_single
end type
type sle_cribnr from singlelineedit within w_aabs_report_parameters_single
end type
type cb_cancel from commandbutton within w_aabs_report_parameters_single
end type
type cb_ok from commandbutton within w_aabs_report_parameters_single
end type
type st_3 from statictext within w_aabs_report_parameters_single
end type
type st_2 from statictext within w_aabs_report_parameters_single
end type
type st_1 from statictext within w_aabs_report_parameters_single
end type
type em_period from editmask within w_aabs_report_parameters_single
end type
type em_year from editmask within w_aabs_report_parameters_single
end type
type ddlb_1 from dropdownlistbox within w_aabs_report_parameters_single
end type
type gb_1 from groupbox within w_aabs_report_parameters_single
end type
end forward

global type w_aabs_report_parameters_single from w_response
integer x = 214
integer width = 1587
integer height = 640
boolean controlmenu = false
st_4 st_4
sle_cribnr sle_cribnr
cb_cancel cb_cancel
cb_ok cb_ok
st_3 st_3
st_2 st_2
st_1 st_1
em_period em_period
em_year em_year
ddlb_1 ddlb_1
gb_1 gb_1
end type
global w_aabs_report_parameters_single w_aabs_report_parameters_single

type variables
STR_AABS_REPORT_PARAMETERS_SINGLE		istr_parameters 		// Structure to hold parameters
end variables

forward prototypes
public function integer of_gettaxid ()
public subroutine of_cancel ()
public subroutine of_start ()
end prototypes

public function integer of_gettaxid ();STRING	ls_description
INTEGER	li_taxid = -1

	ls_description = ddlb_1.Text
	DECLARE pDeclTax CURSOR FOR SELECT id FROM tax_tax WHERE description = :ls_description ;
	
	OPEN pDeclTax ;
	
	IF SQLCA.SqlCode <> 0 AND SQLCA.SqlCode <> 100 THEN
		gnv_App.of_SqlError('Cannot retrieve id for selected tax.',SQLCA)
		COMMIT USING SQLCA ;
		CLOSE pDeclTax ;
	ELSE
		DO WHILE SQLCA.SqlCode = 0
			FETCH pDeclTax INTO :li_taxid ;
		LOOP

		IF SQLCA.SqlCode <> 100 THEN
			gnv_App.of_SqlError('Fetch tax id failed',SQLCA)
		END IF
		
		CLOSE pDeclTax ;	
	END IF

	RETURN li_taxid

end function

public subroutine of_cancel ();
	// Put a negative value in the parameters that were valid
	IF istr_parameters.tax_tax_id	= 1 THEN
		istr_parameters.tax_tax_id = -1
	END IF

	IF istr_parameters.year			= 1 THEN
		istr_parameters.year = -1
	END IF
	
	IF istr_parameters.period		= 1 THEN
		istr_parameters.period = -1
	END IF
	
	IF istr_parameters.cribnr		= 1 THEN
		istr_parameters.cribnr = -1
	END IF
	CloseWithReturn( This, istr_parameters )

end subroutine

public subroutine of_start ();
	DebugBreak()

	// Get the values for the parameters
	IF istr_parameters.tax_tax_id	= 1 THEN
		istr_parameters.tax_tax_id = This.of_gettaxid()
	END IF

	IF istr_parameters.year			= 1 THEN
		istr_parameters.year = Integer(em_year.Text)
	END IF
	
	IF istr_parameters.period		= 1 THEN
		istr_parameters.period = Integer(em_period.Text)
	END IF
	
	IF istr_parameters.cribnr		= 1 THEN
		istr_parameters.cribnr = Integer(sle_cribnr.Text)
	END IF
	
	CloseWithReturn( This, istr_parameters )

end subroutine

on w_aabs_report_parameters_single.create
int iCurrent
call super::create
this.st_4=create st_4
this.sle_cribnr=create sle_cribnr
this.cb_cancel=create cb_cancel
this.cb_ok=create cb_ok
this.st_3=create st_3
this.st_2=create st_2
this.st_1=create st_1
this.em_period=create em_period
this.em_year=create em_year
this.ddlb_1=create ddlb_1
this.gb_1=create gb_1
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.st_4
this.Control[iCurrent+2]=this.sle_cribnr
this.Control[iCurrent+3]=this.cb_cancel
this.Control[iCurrent+4]=this.cb_ok
this.Control[iCurrent+5]=this.st_3
this.Control[iCurrent+6]=this.st_2
this.Control[iCurrent+7]=this.st_1
this.Control[iCurrent+8]=this.em_period
this.Control[iCurrent+9]=this.em_year
this.Control[iCurrent+10]=this.ddlb_1
this.Control[iCurrent+11]=this.gb_1
end on

on w_aabs_report_parameters_single.destroy
call super::destroy
destroy(this.st_4)
destroy(this.sle_cribnr)
destroy(this.cb_cancel)
destroy(this.cb_ok)
destroy(this.st_3)
destroy(this.st_2)
destroy(this.st_1)
destroy(this.em_period)
destroy(this.em_year)
destroy(this.ddlb_1)
destroy(this.gb_1)
end on

event open;

STRING								ls_description			// Description of Tax

	// ************************************************************
	// Get the structure
	// ************************************************************
	istr_parameters = Message.PowerObjectParm
	
	// ************************************************************
	// Center this window over the calling window
	// ************************************************************
	IF istr_parameters.X + istr_parameters.Y + istr_parameters.Width + istr_parameters.Height > 0 THEN
		This.X = istr_parameters.X + (istr_parameters.Width / 2) - (This.Width / 2)
		This.Y = istr_parameters.Y + (istr_parameters.Height/ 2) - (This.Height/ 2)
	END IF
		
	// ************************************************************
	// Get the values from the structure
	// ************************************************************
	IF NOT ISNULL(istr_parameters.title) AND istr_parameters.title <> "" THEN
		This.Title = istr_parameters.Title
	ELSE
		This.Title = "Report details"
	END IF
		
	IF istr_parameters.tax_tax_id = 0 THEN
		ddlb_1.Enabled = False
	ELSE
		// ************************************************************
		// Populate the ddlb
		// ************************************************************
		// changed by BR 10/2012
		ddlb_1.Reset()
		DECLARE pDeclTax CURSOR FOR 
			SELECT description 
			FROM tax_tax 
			WHERE declaration = 1 
			AND ( 
				(id IN (4,5,6, 1,30,72,73) AND 25 IN (SELECT group_name FROM security_groupings WHERE user_name = USER_NAME() ) )
				OR 
				(id IN (1) AND 1 IN (SELECT group_name FROM security_groupings WHERE user_name = USER_NAME() ) )
				)
			ORDER BY description 
			USING SQLCA ;
		
		OPEN pDeclTax ;
		
		IF SQLCA.SqlCode <> 0 AND SQLCA.SqlCode <> 100 THEN
			gnv_App.of_SqlError('Cannot retrieve declaration taxes descriptions.',SQLCA)
			COMMIT USING SQLCA ;
			CLOSE pDeclTax ;
		ELSE
			DO WHILE SQLCA.SqlCode = 0
				FETCH pDeclTax INTO :ls_description ;
				IF SQLCA.SQLCode = 0 THEN 
					ddlb_1.AddItem(ls_description)
				END IF
			LOOP
			IF SQLCA.SqlCode <> 100 THEN
				gnv_App.of_SqlError('Fetch declaration types descriptions failed',SQLCA)
			END IF
			
			CLOSE pDeclTax ;	
		END IF
		
	END IF
		
	IF istr_parameters.year			= 0 THEN
		em_year.Enabled = False
	ELSE
		// *******************************************************************
		// Set values for year, make default last month
		// *******************************************************************
		IF Month( Today() ) > 1 THEN
			This.em_Year.Text = String( Year( Today() ) )
		ELSE
			This.em_Year.Text = String( Year( Today() ) - 1 )
		END IF
	END IF
	
	IF istr_parameters.period		= 0 THEN
		em_period.Enabled = False
	ELSE
		// *******************************************************************
		// Set values for period, make default last month
		// *******************************************************************
		IF Month( Today() ) > 1 THEN
			This.em_Period.Text = String( Month(Today() ) - 1 )
		ELSE
			This.em_Period.Text = String( Month(Today() ) + 11)
		END IF
	END IF

	
end event

type st_4 from statictext within w_aabs_report_parameters_single
integer x = 77
integer y = 374
integer width = 168
integer height = 64
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
long backcolor = 67108864
string text = "Cribnr:"
boolean focusrectangle = false
end type

type sle_cribnr from singlelineedit within w_aabs_report_parameters_single
integer x = 249
integer y = 362
integer width = 607
integer height = 90
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

type cb_cancel from commandbutton within w_aabs_report_parameters_single
integer x = 1192
integer y = 138
integer width = 344
integer height = 93
integer taborder = 50
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
string text = "Cancel"
end type

event clicked;Parent.of_cancel()
end event

type cb_ok from commandbutton within w_aabs_report_parameters_single
integer x = 1192
integer y = 32
integer width = 344
integer height = 93
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
string text = "OK"
end type

event clicked;Parent.of_start()
end event

type st_3 from statictext within w_aabs_report_parameters_single
integer x = 77
integer y = 275
integer width = 168
integer height = 64
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
long backcolor = 67108864
string text = "Period:"
boolean focusrectangle = false
end type

type st_2 from statictext within w_aabs_report_parameters_single
integer x = 77
integer y = 186
integer width = 168
integer height = 64
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
long backcolor = 67108864
string text = "Year:"
boolean focusrectangle = false
end type

type st_1 from statictext within w_aabs_report_parameters_single
integer x = 77
integer y = 93
integer width = 168
integer height = 64
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
long backcolor = 67108864
string text = "Tax:"
boolean focusrectangle = false
end type

type em_period from editmask within w_aabs_report_parameters_single
integer x = 249
integer y = 269
integer width = 282
integer height = 80
integer taborder = 30
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
string mask = "##"
boolean spin = true
double increment = 1
string minmax = "1~~12"
end type

type em_year from editmask within w_aabs_report_parameters_single
integer x = 249
integer y = 176
integer width = 282
integer height = 80
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
string mask = "####"
boolean spin = true
double increment = 1
string minmax = "1990~~2999"
end type

type ddlb_1 from dropdownlistbox within w_aabs_report_parameters_single
integer x = 241
integer y = 80
integer width = 889
integer height = 400
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
string text = "none"
borderstyle borderstyle = stylelowered!
end type

type gb_1 from groupbox within w_aabs_report_parameters_single
integer x = 40
integer y = 10
integer width = 1115
integer height = 464
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 8388608
long backcolor = 67108864
string text = "Parameters for report"
end type

