#!/usr/local/qddb/bin/qwish -f
#
# setup.tcl --
#
#     This module handles the Setup window.  Before Qba can be
#     run, the user must launch the setup program to initialize
#     things like Next Client Number, etc...
#     Qddb Fx library does most of the work.
#
set tcl_precision 17
itcl_class Setup {
    constructor {config} {
	wm title . $title
	wm withdraw .
	if {[catch "qddb_schema open Setup" s] != 0} {
	    puts "Cannot open Schema for relation: [lindex $argv 0]\n$s"; exit 1
	}
	Fx:Init $s
	Fx_Menubar menubar -w .mb -schema $s -array gv_myattr \
		-config_dir .client_config \
		-restrict [glob ~]/.qba_config/Setup
	set gv_search_entry [menubar SearchForEntry]
	frame .f1 -relief groove -bd 4
	frame .f1.a
	frame .f1.b
	frame .f1.c
	frame .f1.d
	frame .f1.e
	frame .f1.f
	Fx_Entry nin -w .f1.a.nin -setschema $s \
		-searchfor_entry $gv_search_entry \
		-attr InvoiceNumber -restrict [glob ~]/.qba_config/Setup
	Fx_Entry nen -w .f1.b.nen -attr EstimateNumber
	Fx_Entry ncn -w .f1.c.ncn -attr ClientID
	pack .f1 -side top -fill x -expand yes
	pack .f1.a .f1.b .f1.c .f1.d .f1.e .f1.f -side top -fill x -expand yes
	pack .f1.a.nin -side left -fill x -expand yes
	pack .f1.b.nen -side left -fill x -expand yes
	pack .f1.c.ncn -side left -fill x -expand yes
	.f1.a.nin.f_0.l            configure -text "Next Invoice #:" -width 18
	.f1.b.nen.f_0.l            configure -text "Next Estimate #:" -width 18
	.f1.c.ncn.f_0.l            configure -text "Next Client #:" -width 18

	#
	# Restore the window and do init stuff
	#
	menubar configure -instances [Fx_Entry::GetInstances] \
		-frames [Fx_Frame::GetInstances]
	menubar SearchModeProc
	set k [Fx_QddbSearchParser::MultiSearch $s {.*} on InvoiceNumber]
	set mykey [qddb_keylist get $k]
	menubar configure -afterpost_modes {
	    .mb.modes.menu entryconfigure 0 -state disabled
	    .mb.modes.menu entryconfigure 1 -state disabled
	}
	menubar configure -afterpost_edit {
	    .mb.edit.menu entryconfigure 7 -state disabled
	}
	if {[llength $mykey] == 0} {
	    menubar AddModeProc
	} else {
	    menubar SetLastSearch [qddb_rows select -attrs InvoiceNumber \
		    -print InvoiceNumber $k]
	    menubar ChangeModeProc 0
	}
	wm deiconify .
    }
    method config {config} {}
    public title "QBA: Setup" {}
    public rootdir /usr/local/Qba/bin {}
    public bitmapdir /usr/local/Qba/bitmaps {}
    public fx_config_dir .client_config
}
lappend auto_path $qddb_library/fx $blt_library /usr/local/Qba/bin/library
Setup setup
