namespace eval ::QW::NEWVIEWS {} namespace eval ::QW::NEWVIEWS::IMPORTER {} ::set ::QW::NEWVIEWS::IMPORTER::journal_experiment 1; itcl::class ${::qw::script::namespace}::IMPORTER { inherit itk::Toplevel; protected variable _export_version_minimum 73; protected variable _export_procedure_name "NVEXPORT"; protected variable _exported_file_name $::qw::dosimport(import_file_name); protected variable _manager ""; protected variable _database ""; protected variable _status ""; protected variable _table; protected variable _database_directory ""; protected variable _database_path ""; protected variable _exported_path ""; protected variable _exported_handle ""; protected variable _exported_seek 0; protected variable _access ""; protected variable _import_action ""; protected variable _current_fiscal_year_end ""; protected variable _purge_audit_sequence_number 0; protected variable _abort_requested 0; protected variable _is_aborted 0; protected variable _suspended_state_variable_id ""; protected variable _suspended_status ""; protected variable _accounts_have_been_processed 0; protected variable _totaltos_have_been_processed 0; protected variable _commit_sequence 0; protected variable _commit_limit 100; protected variable _seconds 0; protected variable _stopwatch ""; protected variable _notesconvert_done 0; protected variable _in_journalentry 0; protected variable _options ""; protected variable _account_class_array; protected variable _account_totalto_array; protected variable _end_of_import_file_reached 0; protected variable _history_errors 0; protected variable _history_error_list ""; protected variable _employees_have_been_processed 0; protected variable _employees_have_been_counted 0; protected variable _payrolls_have_been_processed 0; protected variable _payruns_have_been_processed 0; protected variable _account_preprocessing_is_done 0; protected variable _account_postprocessing_is_done 0; protected variable _account_preprocessing_in_progress 0; protected variable _account_postprocessing_in_progress 0; protected variable _compression_headers_done 0; protected variable _pre_compression_post_shutdown_done 0; protected variable _yearly_res_begin_date [::qw::date::null]; protected variable _monthly_res_begin_date [::qw::date::null]; protected variable _daily_res_begin_date [::qw::date::null]; protected variable _full_res_begin_date [::qw::date::null]; protected variable _compression_import_datums; # Array of transaciton import datums, indexed by transaction address. protected variable _prefix ""; protected variable _idPrefix ""; protected variable _idDescription ""; protected variable _idprefix ""; protected variable _slashIdPrefix ""; protected variable _is_batch 0; protected variable _batch_number 1; protected variable _batch_type ""; protected variable _batch_ledger_items_per_batch 1000; protected variable _batch_ledger_items_at_load 0; protected variable _batch_account_items_per_batch 1000; protected variable _batch_account_items_at_load 0; protected variable _batch_totalto_items_per_batch 1000; protected variable _batch_totalto_items_at_load 0; protected variable _batch_employee_items_per_batch 100; protected variable _batch_employee_items_at_load 0; protected variable _batch_compression_items_at_load 0; protected variable _batch_compression_items_per_batch 1000; protected variable _batch_notesconvert_items_at_load 0; protected variable _batch_notesconvert_items_per_batch 1000; protected variable _batch_history_items_at_load 0; protected variable _batch_history_items_per_batch 1000; protected variable _batch_budget_items_at_load 0; protected variable _batch_budget_items_per_batch 1000; protected variable _batch_notesconvert_class ""; protected variable _batch_notesconvert_account ""; protected variable _batch_history_class ""; protected variable _batch_history_account ""; protected variable _batch_budget_account ""; protected variable _geometry_at_shutdown ""; protected variable _nplSetupPArray; protected variable _nplSetupSArray; protected variable _awReportList ""; protected variable _payrollSuffixArray; protected variable _payroll_list ""; protected variable _procedureRecordArray; protected variable _accountNotesArray; protected variable _accountRecordsArray; protected variable _payrunFieldsArray; protected variable _setupqFieldsArray; protected variable _reportPayPeriodArray; protected variable _employee_id_array; protected variable _employee_list ""; protected variable _timeStats; protected variable _payrunProcedureName ""; protected variable _accountClass; protected variable _payCodesArray; protected variable _payrollCountry ""; protected variable _payrollLibrary ""; protected variable _payrollVersion ""; protected variable _payroll_is_installed 0; protected variable _netPayRoot ""; protected variable _payruns_array; protected variable _purchase_tax_library "NV1"; protected variable _sales_tax_library "NV1"; protected variable _gst_rebate_percent "100"; protected variable _compressionHeaders; protected variable _compressionItems; protected variable _save_audit_state ""; protected variable _save_is_avoiding_date_range_errors_state 0; protected variable _is_importing 0; protected variable _quantity 0; protected variable _description 0; protected variable _port ""; protected variable _ip_address ""; protected variable _socket ""; protected variable _command_method "FILE"; protected variable _is_paused 0; protected variable _after_id ""; protected variable _dde_master_service ""; protected variable _dde_slave ""; protected variable _dde_master_name ""; protected variable _payroll_convert_notes ""; public method constructor {args} { ::set ::qw::control(account_retotal_memory_blowout_fix_is_enabled) 0; ::set _batch_type ""; ::set _is_batch 0; ::set _command_method "FILE"; ::set _suspended_state_variable_id "::BATCH_IMPORT_IS_SUSPENDED_[::qw::id_factory]"; #// a global variable ::set $_suspended_state_variable_id 0; ::set Index [::lsearch -exact [::string tolower $::argv] "-batch"]; ::if {$Index>=0} { ::set _batch_type "DOS"; ::set _is_batch 1; ::set ::argv [::lreplace $::argv $Index $Index]; ::set Index [::lsearch -exact [::string tolower $::argv] "-batch_type"]; ::if {$Index>=0} { ::set _batch_type [::string toupper [::lindex $::argv [::expr $Index+1]]]; ::set ::argv [::lreplace $::argv $Index [::expr $Index+1]]; ::switch -- $_batch_type { "DOS" {} "TCL" {} default { ::qw::throw [::sargs \ .text "Encountered invalid batch_type arg \"$_batch_type\" in command-line.\n-batch_type must be \"DOS\" or \TCL\"." \ .help_id 271820050404143850 \ ]; ;} } } ::if {$_batch_type eq "TCL"} { ::set Index [::lsearch -exact [::string tolower $::argv] "-command_method"]; ::if {$Index>=0} { ::set _command_method [::string toupper [::lindex $::argv [::expr $Index+1]]]; ::set ::argv [::lreplace $::argv $Index [::expr $Index+1]]; ::switch -- $_command_method { "FILE" {} "TCPIP" {} "PIPE" {} "DDE" {} default { ::qw::throw [::sargs \ .text "Encountered invalid command_method arg \"$_command_method\" in command-line.\n-command_method must be \"FILE\", \"TCPIP\", \"DDE\", or \PIPE\"." \ .help_id 271820050404143900 \ ]; ;} } } ::if {$_command_method eq "TCPIP"} { ::set Index [::lsearch -exact [::string tolower $::argv] "-port"]; ::if {$Index<0} { ::qw::throw [::sargs \ .text "No -port arg found for command_method TCP" \ .help_id 271820050404143910 \ ]; ;} ::set _port [::lindex $::argv [::expr $Index+1]]; ::set ::argv [::lreplace $::argv $Index [::expr $Index+1]]; ::set Index [::lsearch -exact [::string tolower $::argv] "-ip_address"]; ::if {$Index<0} { ::qw::throw [::sargs \ .text "No -ip_address arg found for command_method TCP" \ .help_id 271820050404143920 \ ]; ;} ::set _ip_address [::lindex $::argv [::expr $Index+1]]; ::set ::argv [::lreplace $::argv $Index [::expr $Index+1]]; } ::if {$_command_method eq "DDE"} { ::set Index [::lsearch -exact [::string tolower $::argv] "-dde_slave"]; ::if {$Index<0} { ::qw::throw [::sargs \ .text "No -dde_slave arg found for command_method DDE" \ .help_id 271820050404143930 \ ]; ;} ::set _dde_slave [::lindex $::argv [::expr $Index+1]]; ::set ::argv [::lreplace $::argv $Index [::expr $Index+1]]; ::set Index [::lsearch -exact [::string tolower $::argv] "-dde_master"]; ::if {$Index<0} { ::qw::throw [::sargs \ .text "No -dde_master arg found for command_method DDE" \ .help_id 271820050404143940 \ ]; ;} ::set _dde_master_service [::lindex $::argv [::expr $Index+1]]; ::set ::argv [::lreplace $::argv $Index [::expr $Index+1]]; ::set Index [::lsearch -exact [::string tolower $::argv] "-dde_master_name"]; ::if {$Index<0} { ::qw::throw [::sargs \ .text "No -dde_master_name arg found for command_method DDE" \ .help_id 271820050404143950 \ ]; ;} ::set _dde_master_name [::lindex $::argv [::expr $Index+1]]; ::set ::argv [::lreplace $::argv $Index [::expr $Index+1]]; } } communications_init; } ::set ArgV [::string tolower $::argv]; ::set _options [::sargs::+= $::qw::widget::default [::subst { /header {} /table {} /status {} /button {} }]]; ::if {1} { ::array set _table { home-doit 1 oddsAndEnds-doit 1 report-doit 1 account-doit 1 journal-doit 1 transaction-doit 1 journalentry-doit 1 procedures-doit 1 procedure-doit 1 printers-doit 1 printer-doit 1 totaltos-doit 1 checkBooksHistory-doit 1 } } else { ::array set _table { home-doit 1 oddsAndEnds-doit 1 report-doit 1 account-doit 1 journal-doit 1 transaction-doit 0 journalentry-doit 0 procedures-doit 0 procedure-doit 0 printers-doit 0 printer-doit 0 totaltos-doit 1 checkBooksHistory-doit 0 } } ::array set _table { reports-description "Reports" general_accounts-description "General Accounts" bank_accounts-description "Bank Accounts" sales_accounts-description "Sales Accounts" payroll_accounts-description "Payroll Accounts" expense_accounts-description "Expense Accounts" cgs_accounts-description "CGS Accounts" ap_accounts-description "Supplier Accounts" ar_accounts-description "Customer Accounts" inventory_accounts-description "Inventory Accounts" total_accounts-description "Total Accounts" journals-description "Journals" totaltos-description "TotalTos" notesconvert-description "Convert Account Notes" journalEntries-description "Journal Entries" ledgerItems-description "Ledger Items" distributions-description "Distribution Items" compressionHeaders-description "Compression Transactions" compressionItems-description "Compression Items" procedures-description "Procedures" printers-description "Printers" notes-description "Notes Lines" records-description "Record View Items" payrolls-description "Payrolls" employees-description "Employees" budgets-description "Budget Items" history-description "Account History Check" } ::if {$::qw::control(donor_management_is_enabled)} { ::array set _table { donor_accounts-description "Donor Accounts" program_revenue_accounts-description "Program Revenue Accounts" } } ::set _table(names) ""; ::lappend _table(names) "reports"; ::lappend _table(names) "general_accounts"; ::lappend _table(names) "bank_accounts"; ::lappend _table(names) "sales_accounts"; ::lappend _table(names) "payroll_accounts"; ::lappend _table(names) "expense_accounts"; ::lappend _table(names) "cgs_accounts"; ::lappend _table(names) "ap_accounts"; ::lappend _table(names) "ar_accounts"; ::lappend _table(names) "inventory_accounts"; ::if {$::qw::control(donor_management_is_enabled)} { ::lappend _table(names) "donor_accounts"; ::lappend _table(names) "program_revenue_accounts"; } ::lappend _table(names) "total_accounts"; ::lappend _table(names) "journals"; ::lappend _table(names) "notesconvert"; ::lappend _table(names) "totaltos"; ::lappend _table(names) "payrolls"; ::lappend _table(names) "employees"; ::lappend _table(names) "journalEntries"; ::lappend _table(names) "ledgerItems"; ::lappend _table(names) "distributions"; ::lappend _table(names) "compressionHeaders"; ::lappend _table(names) "compressionItems"; ::lappend _table(names) "procedures"; ::lappend _table(names) "printers"; ::lappend _table(names) "notes"; ::lappend _table(names) "records"; ::lappend _table(names) "budgets"; ::if {[::info exists _table(checkBooksHistory-doit)]} { ::if {$_table(checkBooksHistory-doit)} { ::array set _table { history-description "Account History Check" } ::lappend _table(names) "history"; } } ::foreach Name $_table(names) { ::set _table($Name-processed) 0; ::set _table($Name-target) 0; } ::set _table(all_accounts-processed) 0; ::set _table(all_accounts-target) 0; ::array set _account_class_array {}; ::array set _account_totalto_structure {}; ::array set _timeStats {Names ""}; ::set _payroll_is_installed 0; ::set _payrollCountry ""; ::set _payrollLibrary ""; ::set _payrollVersion ""; ::set _netPayRoot ""; ::array set _payrunFieldsArray {}; ::array set _setupqFieldsArray {}; ::array set _payCodesArray {}; ::array set _employee_id_array {}; ::array set _payruns_array {}; ::array set _compressionHeaders {}; ::array set _compressionItems {}; ::array set _compression_import_datums {}; set LabelBorderWidth 0.5m; set ControlPadding 1m; ::set Me $itk_interior; ::frame $Me.table; ::frame $Me.controls -height 2 -borderwidth 1m -relief sunken; ::button $Me.controls.action -borderwidth $ControlPadding -font [option /button.font]; ::button $Me.controls.help -text Help -borderwidth $ControlPadding -command [::list ::qwhelp -webpageid 314120010102170123] -font [option /button.font]; ::label $Me.status -textvariable [::itcl::scope _status] -relief sunken -borderwidth $LabelBorderWidth -anchor w -font [option /status.font]; ::pack $Me.table -expand yes -fill both -padx 4 -pady 4; ::pack $Me.controls -expand no -fill x -padx $ControlPadding -pady $ControlPadding; ::pack $Me.controls.action -side left -expand yes -fill x -padx $ControlPadding -pady $ControlPadding; ::pack $Me.controls.help -side left -expand yes -fill x -padx $ControlPadding -pady $ControlPadding; ::pack $Me.status -fill x -padx 4 -pady 4; ::wm group $itk_component(hull) .; ::label $Me.table._titlelabel -text "Type" -font [option /header.font] -relief raised -borderwidth $LabelBorderWidth -width 22 -anchor c ::label $Me.table._titletarget -text "Count" -font [option /header.font] -relief raised -borderwidth $LabelBorderWidth -width 11 -anchor c ::label $Me.table._titleitems -text "Done" -font [option /header.font] -relief raised -borderwidth $LabelBorderWidth -width 11 -anchor c ::label $Me.table._titlecompletion -text "Percent Done" -font [option /header.font] -relief raised -borderwidth $LabelBorderWidth -width 30 -anchor c ::set Row 0; ::set Column 0; ::grid $Me.table._titlelabel -row $Row -column $Column -sticky ewns;::incr Column; ::grid $Me.table._titletarget -row $Row -column $Column -sticky ewns;::incr Column; ::grid $Me.table._titleitems -row $Row -column $Column -sticky ewns;::incr Column; ::grid $Me.table._titlecompletion -row $Row -column $Column -sticky ewns;::incr Column; ::incr Row; ::foreach Name [tableNames] { ::if {[::string first "compress" $Name]==0} { ::continue; } ::label $Me.table.${Name}label -text [::set [::itcl::scope _table($Name-description)]] -font [option /table.font] -relief sunken -borderwidth $LabelBorderWidth -width 22 -anchor e; ::label $Me.table.${Name}target -textvariable [::itcl::scope _table($Name-target)] -font [option /table.font] -relief sunken -borderwidth $LabelBorderWidth -width 11 -anchor e; ::label $Me.table.${Name}items -textvariable [::itcl::scope _table($Name-processed)] -font [option /table.font] -relief sunken -borderwidth $LabelBorderWidth -width 11 -anchor e; ::QW::WIDGET::COMPLETION_PERCENTAGE $Me.table.${Name}completion -limitvariable [::itcl::scope _table($Name-target)] -valuevariable [::itcl::scope _table($Name-processed)]; ::set Column 0; ::grid $Me.table.${Name}label -row $Row -column $Column -sticky ewns;::incr Column; ::grid $Me.table.${Name}target -row $Row -column $Column -sticky ewns;::incr Column; ::grid $Me.table.${Name}items -row $Row -column $Column -sticky ewns;::incr Column; ::grid $Me.table.${Name}completion -row $Row -column $Column -sticky ewns;::incr Column; ::grid rowconfigure $Me.table $Row -weight 1; ::incr Row; } ::grid columnconfigure $Me.table 0 -weight 1; ::grid columnconfigure $Me.table 1 -weight 1; ::grid columnconfigure $Me.table 2 -weight 1; ::grid columnconfigure $Me.table 3 -weight 1; ::eval itk_initialize $args; ::wm withdraw $itk_component(hull); ::wm protocol $itk_component(hull) WM_DELETE_WINDOW [::itcl::code $this abort_requested]; ::set Index [::lsearch -exact $ArgV "-nocontrols"]; ::if {$Index>=0} { ::pack forget $Me.controls; ::set ::argv [::lreplace $ArgV $Index $Index]; } ::if {$_is_batch} { batch_startup; } else { ::if {![::info exists ::qw::script::env(manager)]||$::qw::script::env(manager) eq ""} {import_error "[::info script] should be run from a NewViews database.";} ::set _manager $::qw::script::env(manager); } ::set _database [$_manager cpp_database]; ::set _access [$_database cpp_access]; ::set _database_path [$_database cpp_database_path]; ::set _database_directory [::file dirname $_database_path]; ::if {[::file exists [::file join $_database_directory $_exported_file_name]]} { ::set _exported_path [::file join $_database_directory $_exported_file_name]; } ::if {$_is_batch} { ::wm withdraw . ::qw::status::destroy; centerOnScreen; ::update; ::update idletasks; import; ::return $this; } ::if {$_exported_path eq ""} { $Me.controls.action configure -text "Press to select exported file." -command [::itcl::code $this directory_select] configure -title "Ready to select exported file." status "Ready to select exported file ..." } else { $Me.controls.action configure -text "Press to begin import." -borderwidth $ControlPadding -command [::itcl::code $this import] -font [option /button.font]; configure -title "Ready to import newviews data." status "Ready to import newviews data into $_database_path ..." } ::focus $Me.controls.action; ::bind $Me.controls.action "$Me.controls.action invoke"; ::after idle [::itcl::code $this centerOnScreen]; ::qw::toplevel_add [::sargs .path $Me]; ::return $this; } public method destructor {} { ::if {$_stopwatch ne ""} {::itcl::delete object $_stopwatch;} ::if {$_exported_handle ne ""} { ::close $_exported_handle; ::set _exported_handle ""; } stop_timer_events; communications_close; ::set ::qw::control(account_retotal_memory_blowout_fix_is_enabled) 1; } method batch_startup {} { ::set Args [::string tolower $::argv]; ::set Index [::lsearch -exact $Args "-directory"]; ::if {$Index>=0} { ::set _database_directory [::lindex $Args [::incr Index]]; ::if {[::string index $_database_directory 0] eq "\{" && [::string index $_database_directory end] eq "\}"} { ::set _database_directory [::string range $_database_directory 1 end-1]; } ::set _database_path [::file join $_database_directory database.nv2]; } ::if {$_database_directory eq ""} {import_error "The database directory was not specified.";} ::if {![::file exists $_database_path]} { ::if {[::file exists "$_database_directory/$_exported_file_name.control"]} { import_error "Found file $_exported_file_name.control but no database." } ::qw::try { [::qw::odb::factory database] cpp_create [::sargs .database_path $_database_path .database_type "application" .access "singleuser"]; ::set _database [::qw::odb::factory database]; ::set _manager $_database; $_database cpp_database_open [::sargs .database_path $_database_path .access "singleuser"]; ::if {[$_manager cpp_find "/OBJECT"] eq ""} { ::qw::script::source \ .script.path [::file join $::qw_library object install.qw_script] \ .database $_manager \ .command application \ ; } ::if {[$_manager cpp_find "/OBJECT/SYSTEM/USER"] eq ""} { status "[::file normalize $_database_path] installing system classes."; ::qw::script::source \ .script.path [::file join $::qw_library object system install.qw_script] \ .database $_manager \ .command application \ ; } ::set ClientdataBefore [$_database cpp_clientdata_get]; ::set ClientdataAfter $ClientdataBefore; ::sargs::var::set ClientdataAfter .semiloops_are_allowed 1; $_database cpp_clientdata_set .before $ClientdataBefore .after $ClientdataAfter; $_manager cpp_commit .commit_before_skip 1; } catch Exception { ::puts $::errorInfo; ::return [::qw::dialog::error [::qw::exception::parent "Could not create database." $Exception]]; } } else { ::qw::try { ::set _database [::qw::odb::factory database]; ::set _manager $_database; $_database cpp_database_open [::sargs .database_path $_database_path .access "singleuser"]; } catch Exception { ::return [::qw::dialog::error [::qw::exception::parent "Could not open database." $Exception]]; } } ::set Path [::file join $_database_directory "$_exported_file_name.control"]; ::if {[::file exists $Path]} { ::set Handle [::open $Path r]; ::set Header [::read $Handle]; ::close $Handle; ::set _batch_number [::sargs::get $Header ".batch_number"]; ::incr _batch_number; ::set _exported_seek [::sargs::get $Header ".seek"]; ::set _seconds [::sargs::get $Header ".seconds"]; ::foreach Name $_table(names) { ::set _table($Name-processed) [::sargs::get $Header ".processed.$Name"]; ::set _table($Name-target) [::sargs::get $Header ".target.$Name"]; } ::set _batch_ledger_items_at_load [::sargs::get $Header ".processed.ledgerItems"]; ::set _batch_account_items_at_load [::sargs::get $Header ".processed.all_accounts"]; ::set _table(all_accounts-processed) [::sargs::get $Header ".processed.all_accounts"]; ::set _table(all_accounts-target) [::sargs::get $Header ".target.all_accounts"]; ::set _batch_totalto_items_at_load $_table(totaltos-processed); ::set _batch_employee_items_at_load $_table(employees-processed); ::set _batch_compression_items_at_load $_table(compressionItems-processed); ::set _batch_notesconvert_items_at_load $_table(notesconvert-processed); ::set _batch_history_items_at_load $_table(history-processed); ::set _batch_budget_items_at_load $_table(budgets-processed); ::array set _account_class_array [::sargs::get $Header ".account_class_array"]; ::array set _account_totalto_array [::sargs::get $Header ".account_totalto_array"]; ::array set _payruns_array [::sargs::get $Header ".payruns_array"]; ::set _compression_headers_done [::sargs::get $Header ".compression_headers_done"]; ::set _notesconvert_done [::sargs::get $Header ".notesconvert_done"]; ::set _payroll_is_installed [::sargs::get $Header ".payroll_is_installed"]; ::set _employees_have_been_processed [::sargs::get $Header ".employees_have_been_processed"]; ::set _employees_have_been_counted [::sargs::get $Header ".employees_have_been_counted"]; ::set _history_error_list [::sargs::get $Header ".history_error_list"]; ::set _accounts_have_been_processed [::sargs::get $Header ".accounts_have_been_processed"]; ::set _batch_notesconvert_class [::sargs::get $Header ".batch_notesconvert_class"]; ::set _batch_notesconvert_account [::sargs::get $Header ".batch_notesconvert_account"]; ::set _batch_history_class [::sargs::get $Header ".batch_history_class"]; ::set _batch_history_account [::sargs::get $Header ".batch_history_account"]; ::set _batch_budget_account [::sargs::get $Header ".batch_budget_account"]; ::set _totaltos_have_been_processed [::sargs::get $Header ".totaltos_have_been_processed"]; ::set _payrolls_have_been_processed [::sargs::get $Header ".payrolls_have_been_processed"]; ::set _payruns_have_been_processed [::sargs::get $Header ".payruns_have_been_processed"]; ::set _payroll_list [::sargs::get $Header ".payroll_list"]; ::eval ::set _employee_list [::sargs::get $Header ".employee_list"]; ::set _geometry_at_shutdown [::sargs::get $Header ".geometry_at_shutdown"]; ::set _account_preprocessing_is_done [::sargs::get $Header ".account_preprocessing_is_done"]; ::set _account_postprocessing_is_done [::sargs::get $Header ".account_postprocessing_is_done"]; ::set _account_preprocessing_in_progress [::sargs::get $Header ".account_preprocessing_in_progress"]; ::set _account_postprocessing_in_progress [::sargs::get $Header ".account_postprocessing_in_progress"]; ::set _pre_compression_post_shutdown_done [::sargs::get $Header ".pre_compression_post_shutdown_done"]; ::array set _employee_id_array [::sargs::get $Header ".employee_id_array"]; ::array set _compressionHeaders [::sargs::get $Header ".compressionHeaders"]; ::array set _compressionItems [::sargs::get $Header ".compressionItems"]; ::foreach Name {yearly monthly daily full} { ::if {![::sargs::exists $Header ".${Name}_res_begin_date"]} {::continue;} ::set _${Name}_res_begin_date [::sargs::get $Header ".${Name}_res_begin_date"]; } ::file delete $Path; } ::foreach Name {ledger account totalto employee compression notesconvert history budget} { ::set Index [::lsearch -exact $Args "-${Name}-items"]; ::if {$Index<0} {::continue;} ::incr Index; ::set _batch_${Name}_items_per_batch [::lindex $Args $Index]; } ::set _idprefix ""; ::set _iddescription ""; ::foreach Name { yearly_res_begin_date monthly_res_begin_date daily_res_begin_date full_res_begin_date idprefix iddescription } { ::set Index [::lsearch -exact $Args "-${Name}"]; ::if {$Index<0} {::continue;} ::incr Index; ::set _${Name} [::lindex $Args $Index]; } ::set _idPrefix $_idprefix; ::set _idDescription $_iddescription; ::if {[::qw::date::difference $_full_res_begin_date $_daily_res_begin_date "day"]<0} { import_error "Invalid full-res begin date $_full_res_begin_date, date must be >= daily-res begin date $_daily_res_begin_date"; } ::if {[::qw::date::difference $_daily_res_begin_date $_monthly_res_begin_date "day"]<0} { import_error "Invalid daily-res begin date $_daily_res_begin_date, date must be >= monthly-res begin date $_monthly_res_begin_date"; } ::if {[::qw::date::difference $_monthly_res_begin_date $_yearly_res_begin_date "day"]<0} { import_error "Invalid monthly-res begin date $_monthly_res_begin_date, date must be >= yearly-res begin date $_yearly_res_begin_date"; } control_message_send "*READY*" ::return $this; } method close_database {args} { ::if {$_database eq ""} {::return $this;} $_manager cpp_audit_state_set $_save_audit_state; ::incr ::qw::control(progress_window_disable_count) -1; ::set ::qw::control(is_avoiding_date_range_errors) $_save_is_avoiding_date_range_errors_state; $_manager cpp_commit .commit_before_skip 1; ::set _manager ""; $_database cpp_destroy; ::set _database ""; ::return $this; } method write_payroll_notes {} { ::if {$_payroll_convert_notes eq ""} {::return;} ::if {!$_payroll_is_installed} {::return;} ::set Master [$_manager "/OBJECT/NEWVIEWS/PAYROLL/$_payrollCountry$_slashIdPrefix"]; ::set Notes [[$Master ".notes"] odb_get]; ::append Notes \n$_payroll_convert_notes; [$Master ".notes"] odb_set $Notes; commit $Master; ::set _payroll_convert_notes ""; } method batch_shutdown {args} { write_payroll_notes; compression_import_datums_save; status "Closing database ..."; close_database; ::sargs::var::set Header ".batch_number" $_batch_number; ::sargs::var::set Header ".seek" [::tell $_exported_handle]; ::close $_exported_handle; ::set _exported_handle ""; ::sargs::var::set Header ".seconds" [::expr {[$_stopwatch seconds]+$_seconds}]; ::set Done 1; ::foreach Name $_table(names) { ::sargs::var::set Header ".processed.$Name" $_table($Name-processed); ::sargs::var::set Header ".target.$Name" $_table($Name-target); ::if {$_table($Name-processed) != $_table($Name-target)} { ::set Done 0; } } ::sargs::var::set Header ".processed.all_accounts" $_table(all_accounts-processed); ::sargs::var::set Header ".target.all_accounts" $_table(all_accounts-target); ::sargs::var::set Header ".payroll_is_installed" $_payroll_is_installed; ::sargs::var::set Header ".employees_have_been_processed" $_employees_have_been_processed; ::sargs::var::set Header ".employees_have_been_counted" $_employees_have_been_counted; ::sargs::var::set Header ".history_error_list" $_history_error_list; ::sargs::var::set Header ".accounts_have_been_processed" $_accounts_have_been_processed; ::sargs::var::set Header ".notesconvert_done" $_notesconvert_done; ::sargs::var::set Header ".batch_notesconvert_class" $_batch_notesconvert_class; ::sargs::var::set Header ".batch_notesconvert_account" $_batch_notesconvert_account; ::sargs::var::set Header ".batch_history_class" $_batch_history_class; ::sargs::var::set Header ".batch_history_account" $_batch_history_account; ::sargs::var::set Header ".batch_budget_account" $_batch_budget_account; ::sargs::var::set Header ".totaltos_have_been_processed" $_totaltos_have_been_processed; ::sargs::var::set Header ".payrolls_have_been_processed" $_payrolls_have_been_processed; ::sargs::var::set Header ".payruns_have_been_processed" $_payruns_have_been_processed; ::sargs::var::set Header ".payroll_list" $_payroll_list; ::sargs::var::set Header ".employee_list" [::list $_employee_list]; ::sargs::var::set Header ".account_class_array" [::array get _account_class_array]; ::sargs::var::set Header ".account_totalto_array" [::array get _account_totalto_array]; ::sargs::var::set Header ".payruns_array" [::array get _payruns_array]; ::sargs::var::set Header ".geometry_at_shutdown" [::winfo geometry $itk_component(hull)]; ::sargs::var::set Header ".account_preprocessing_is_done" $_account_preprocessing_is_done; ::sargs::var::set Header ".account_postprocessing_is_done" $_account_postprocessing_is_done; ::sargs::var::set Header ".account_preprocessing_in_progress" $_account_preprocessing_in_progress; ::sargs::var::set Header ".account_postprocessing_in_progress" $_account_postprocessing_in_progress; ::sargs::var::set Header ".pre_compression_post_shutdown_done" $_pre_compression_post_shutdown_done; ::sargs::var::set Header ".employee_id_array" [::array get _employee_id_array]; ::sargs::var::set Header ".compression_headers_done" $_compression_headers_done; ::sargs::var::set Header ".compressionHeaders" [::array get _compressionHeaders]; ::sargs::var::set Header ".compressionItems" [::array get _compressionItems]; ::sargs::var::set Header ".yearly_res_begin_date" $_yearly_res_begin_date; ::sargs::var::set Header ".monthly_res_begin_date" $_monthly_res_begin_date; ::sargs::var::set Header ".daily_res_begin_date" $_daily_res_begin_date; ::sargs::var::set Header ".full_res_begin_date" $_full_res_begin_date; ::set Done 0; ::if {[::lindex $args 0] eq "DONE"} {::set Done 1;} ::if {$_import_action eq "process"} { ::if {$Done} { ::if {[::file exists $_exported_path.control]} { ::file delete $_exported_path.control; } ::set Handle [::open $_exported_path.end w+]; } else { ::set Handle [::open $_exported_path.control w+]; } ::puts -nonewline $Handle [::sargs::format .structure $Header]; ::close $Handle; } ::if {$Done} { control_message_send "*IMPORT_COMPLETE*"; ::return; } ::if {$_is_aborted} { control_message_send "*IMPORT_ABORTED*"; } else { control_message_send "*BATCH_COMPLETE*"; } ::qw::shutdown; } public method compression_import_datums_save {} { ::foreach CompressionDate [::array names _compression_import_datums] { status "Saving compression transaction details for [::qw::date::format $CompressionDate {%b %d %Y}]"; ::set Transaction [compressionTransactionGet $CompressionDate]; [$Transaction ".import_datum"] odb_set $_compression_import_datums($CompressionDate); ::unset _compression_import_datums($CompressionDate); } } public method communications_init {} { ::switch -- $_command_method { "FILE" {command_file_watch_start;} "TCPIP" { ::if {[::catch {::set _socket [::socket $_ap_address $_port]} ErrorMessage]} { import_error "Server connect failed: $ErrorMessage"; } ::fconfigure $_socket -buffering line -blocking 0 -translation binary; ::fileevent $_socket readable [::itcl::code $this control_message_receive]; } "PIPE" { ::fconfigure stdin -buffering line -blocking 0; ::fileevent stdin readable [::itcl::code $this control_message_receive]; ::fconfigure stdout -buffering line -blocking 0; } "DDE" { ::package require dde; ::dde servername $_dde_slave; control_message_send "*CONNECT* [::namespace code $this]"; } } } public method communications_close {} { ::switch -- $_command_method { "FILE" {command_file_watch_stop;} "TCPIP" { ::if {$_socket ne ""} { ::if {[::catch {::close $_socket} ErrorMessage]} { import_error "Server disconnect failed: $ErrorMessage"; } ::set _socket ""; } } "PIPE" {} "DDE" { control_message_send "*DISCONNECT* $_dde_slave"; } } } public method command_file_watch_start {} { ::if {$_after_id ne ""} {::return;} ::set _after_id [::after 500 [::itcl::code $this command_file_watch]] } public method command_file_watch_stop {} { ::if {$_after_id eq ""} {::return;} ::after cancel $_after_id; ::set _after_id ""; } public method command_file_watch {} { ::set _after_id ""; command_file_watch_start; ::if {[::file exists [::file join $_database_directory $_exported_file_name.abort]]} { control_message_receive "ABORT"; } ::if {[::file exists [::file join $_database_directory $_exported_file_name.pause]]} { control_message_receive "PAUSE_BEGIN"; } else { control_message_receive "PAUSE_END"; } ::if {[::file exists [::file join $_database_directory $_exported_file_name.dismiss]]} { communications_close; control_message_receive "DISMISS"; } } public method control_message_send {Src} { ::switch -- $_command_method { "TCPIP" { ::puts $_socket $Src; ::flush $_socket; } "PIPE" { ::puts $Src; ::flush stdout; } "FILE" { ::switch -- [::lindex $Src 0] { "*READY*" {::return;} "*ABORT_REQUEST*" {::set Extension "abort_request";} "*BATCH_COMPLETE*" {::set Extension "batch_complete";} "*IMPORT_COMPLETE*" {::set Extension "import_complete";} "*SHUTDOWN*" {::set Extension "shutdown";} "*IMPORT_ABORTED*" { ::if {$_batch_type eq "DOS"} { ::set Extension "error"; } else { ::set Extension "import_aborted"; } } "*ERROR*" {::set Extension "error";::set Src [::lrange $Src 1 end];} "*USER_MESSAGE*" {::puts [::lrange $Src 1 end];::return;} default { ::qw::throw [::sargs \ .text "Importer encountered unknown control message \"$Src\"" \ .help_id 271820050404144000 \ ]; ;} } ::set FileName $_exported_path.$Extension; ::set Handle [::open $FileName w+]; ::puts -nonewline $Handle $Src; ::close $Handle; } "DDE" { ::dde eval -async $_dde_master_service $_dde_master_name importer_message_receive $Src; } } } public method control_message_receive {args} { ::switch -- $_command_method { "TCPIP" {::set Message [::read $_socket];} "PIPE" {::gets stdin Message;} "DDE" - "FILE" {::set Message [::lindex $args 0];} } ::if {$Message eq ""} {::return;} ::switch -- $Message { "PAUSE_BEGIN" {pause_begin;} "PAUSE_END" {pause_end;} "ABORT" {abort;} "DISMISS" { ::if {$_batch_type eq "TCL"&&!$_is_aborted} {dismiss;} } default { ::qw::throw [::sargs \ .text "control_message_receive encountered invalid command \"$Message\"" \ .help_id 271820050404144010 \ ]; ;} } } public method stop_timer_events {} { command_file_watch_stop; } public method status {args} { ::switch -- [::llength $args] { 0 {::return $_status;} 1 { ::if {$_is_aborted} { ::if {$_is_batch} { ::set _status "Import aborted, the import will shut down at the next safe-point."; } else { ::set _status "Import aborted."; } } else { ::set _status [::string range [::lindex $args 0] 0 80]; } ::update; ::if {$_status eq ""} {::return $this;} ::if {$_batch_type eq "TCL"&&$_command_method eq "PIPE"} { ::return $this; } ::qw::status::puts "IMPORTER::status: $_status"; ::return $this; } } ::error "Wrong number of args to IMPORTER::status method."; } public method tableNames {} {::return $_table(names);} public method option {Path} {return [::sargs::get_poly $_options $Path];} public method options {Options} { ::set _options [::sargs::+= $_options $Options]; return $this; } method import_error {Src} { ::if {!$_is_batch} {::qw::throw $Src;} ::if {[::sargs::find_field_value .structure $Src .field .id .value batch_complete]} { batch_shutdown; } control_message_send "*ERROR* $Src"; ::if {$_batch_type eq "TCL"} { communications_close; control_message_send "*SHUTDOWN*"; ::qw::throw $Src; ::qw::shutdown; } ::qw::throw $Src; } method update {} {::update} method manager {} {return $_manager;} method quantity_and_description_set {Object Src} { ::if {[::regexp {(^[0-9\.-]+)( )(.*)} $Src match Quantity Space Description]} { [$Object ".quantity"] odb_set $Quantity; ::if {$Quantity!=0.0} {[$Object ".rate"] odb_set [::expr {[[$Object ".amount"] odb_get]/$Quantity}];} ::set Src $Description; } [$Object ".description"] odb_set $Src; ::return $this; } method report_get {Name} { ::set Name [stringFilter $Name]; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/REPORT$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Name]; ::if {$Reference eq ""} {import_error "Could not find report \"$Name\".";} ::return [$Reference odb_master]; } method account_get {Name} { ::set Name [stringFilter $Name]; ::set Class $_account_class_array($Name); ::if {$Class eq "PAYROLL"} { ::set Class "PAYROLL/$_payrollCountry"; } ::if {$::qw::control(airtech)} { ::if {$Class eq "AR"} { ::set Class "AR/AIRTECH"; } } ::if {$_idPrefix eq "000"} { ::set PathPiece "/TOTAL$_slashIdPrefix"; } else { ::set PathPiece "/$Class$_slashIdPrefix"; } ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT$PathPiece.odb_deriveds.index/name"] odb_find_key ".name" $Name]; ::if {$Reference eq ""} { import_error "Could not find account \"$PathPiece/$Name\"."; } ::return [$Reference odb_master]; } method journal_get {Name} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT/JOURNAL_ACCOUNTS.odb_deriveds.index/name"] odb_find_key ".name" $Name]; ::if {$Reference eq ""} {import_error "Could not find journal \"$Name\".";} return [$Reference odb_master]; } method increment {VarName {Increment 1}} { ::incr _table($VarName) $Increment; ::update; } method stringFilter {Src} { ::return [::string map {\\\{ _ob_ \\\} _cb_ \{ _ob_ \} _cb_} $Src]; } method nameFilter {Src} { ::return [::string map {$ ds * k " " s . d - h & a ~ t ` bq ' q} $Src]; } method text_count {Src} { return [::llength $Src]; } method text_filter {Src} { ::if {$Src eq ""} {return "";} ::set Result ""; ::foreach Line $Src {::append Result "$Line\n";} return $Result; } method home_process {Arg} { ::set Master [$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/HOME"]; ::set Notes [::sargs::get $Arg ".notes"]; ::if {$Notes ne ""} { [$Master ".notes"] odb_set [text_filter $Notes]; increment notes-processed [text_count $Notes]; } ::set Records [::sargs::get $Arg ".records"]; ::if {$Records ne ""} { [$Master ".records"] odb_set [text_filter $Records]; increment records-processed [text_count $Records]; } commit $Master; return $this; } method home_count {Arg} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; return $this; } method oddsAndEnds_process {Arg} { ::set Master [$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/ODDS_AND_ENDS"]; ::set Fields [::sargs::get $Arg ".fields"]; ::if {$Fields ne ""} { [$Master ".fields"] odb_set $Fields; ::set CFYE [::sargs::get $Fields ".current_fiscal_year_end"]; ::if {$CFYE eq "" || $CFYE eq "00000101"} { ::set _current_fiscal_year_end ""; } else { ::set _current_fiscal_year_end [date_normalize [::sargs::get $Fields ".current_fiscal_year_end"]]; } ::if {[::sargs::exists $Fields ".purge_audit_sequence_number"]} { ::set _purge_audit_sequence_number [::sargs::get $Fields ".purge_audit_sequence_number"]; } } ::set Description [::sargs::get $Arg ".description"]; ::if {$Description ne ""} {[$Master ".description"] odb_set $Description;} ::set Notes [::sargs::get $Arg ".notes"]; ::if {$Notes ne ""} { [$Master ".notes"] odb_set [text_filter $Notes]; increment notes-processed [text_count $Notes]; } ::set Records [::sargs::get $Arg ".records"]; ::if {$Records ne ""} { [$Master ".records"] odb_set [text_filter $Records]; increment records-processed [text_count $Records]; } commit $Master; ::return $this; } method oddsAndEnds_count {Arg} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; ::set Fields [::sargs::get $Arg ".fields"]; ::if {$Fields eq ""} {::return $this;} ::set CFYE [::sargs::get $Fields ".current_fiscal_year_end"]; ::if {$CFYE eq "" || $CFYE eq "00000101"} { ::set _current_fiscal_year_end ""; } else { ::set _current_fiscal_year_end [date_normalize [::sargs::get $Fields ".current_fiscal_year_end"]]; } sanity_check_compression_and_fiscal_year_end; ::return $this; } method sanity_check_compression_and_fiscal_year_end {} { ::if {[::qw::date::is_null $_current_fiscal_year_end]} {::return;} ::if {[::qw::date::is_null $_daily_res_begin_date]} {::return;} ::set YearlyHistoryEnd [::qw::date::add $_current_fiscal_year_end year -2]; ::set MonthlyHistoryBegin [::qw::date::add $YearlyHistoryEnd day 1]; ::if {[::qw::date::difference $_monthly_res_begin_date $MonthlyHistoryBegin "day"]>0} { ::qw::throw [::sargs \ .text "Monthly compression date $_monthly_res_begin_date is after the DOS books monthly history start date $MonthlyHistoryBegin." \ .help_id 271820050404144020 \ ]; } } method report_process {Arg} { ::set Name [::sargs::get $Arg ".name"] ::set Master [[$_manager "/OBJECT/NEWVIEWS/REPORT$_slashIdPrefix.odb_deriveds"] odb_factory]; ::set Description [::sargs::get $Arg ".description"]; ::set Name [stringFilter $Name]; ::set Description [stringFilter $Description]; [$Master ".name"] odb_set $Name; ::if {$Description ne ""} {[$Master ".description"] odb_set $Description;} ::set Notes [::sargs::get $Arg ".notes"]; ::if {$Notes ne ""} { [$Master ".notes"] odb_set [text_filter $Notes]; increment notes-processed [text_count $Notes]; } ::set Records [::sargs::get $Arg ".records"]; ::if {$Records ne ""} { [$Master ".records"] odb_set [text_filter $Records]; increment records-processed [text_count $Records]; } commit $Master; status "Report:$Name,$Description" increment reports-processed; batch_check; } method report_count {Arg} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; increment reports-target; } method errors_set {Object Errors} { ::set Import_Datum [[$Object ".import_datum"] odb_get]; ::set Text [::sargs::get $Import_Datum ".errors"]; ::append Text $Errors; ::sargs::var::set Import_Datum ".errors" $Text; [$Object ".import_datum"] odb_set $Import_Datum; ::foreach Error $Errors { status "Error:\t$Error"; } } method journal_count {Arg} { ::set Name [::sargs::get $Arg ".name"]; ::if {$Name eq ""} { increment notes-target; ::return; } increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; increment journals-target; } method journal_process {Arg} { ::array set Args $Arg; ::set Name [::sargs::get $Arg ".name"]; ::if {$Name eq ""} {::return [account_process $Arg];} ::set Description [::string trim [::sargs::get $Arg ".description"]]; ::set Name [stringFilter $Name]; ::set Description [stringFilter $Description]; ::set Journal [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT/JOURNAL_ACCOUNTS.odb_deriveds"] odb_factory]; [$Journal ".name"] odb_set $Name; ::set Status "Journal, $Name" ::if {$Description ne ""} { [$Journal ".description"] odb_set $Description; ::append Status ",$Description" } [$Journal ".tags"] odb_set "financial"; ::if {[::info exists Args(.notes)]} { [$Journal ".notes"] odb_set [text_filter $Args(.notes)] increment notes-processed [text_count $Args(.notes)]; } ::if {[::info exists Args(.records)]} { [$Journal ".records"] odb_set [text_filter $Args(.records)] increment records-processed [text_count $Args(.records)]; } ::if {[::info exists Args(.errors)]} { errors_set $Journal $Args(.errors); } increment journals-processed; commit $Journal; status $Status; } method account_class {Arg} { ::if {[::sargs::get $Arg ".name"] eq ""} {::return "";} ::if {[::sargs::exists $Arg ".total_kids"]&&[::sargs::get $Arg ".total_kids"] ne 0} {::return "TOTAL";} ::set Class [::sargs::get $Arg ".nplclass"]; ::switch -- $Class { "EXP" {::set Class "EXPENSE";} "GL" {::set Class "GENERAL";} "INV" {::set Class "INVENTORY";} "PROGRAM" {::set Class "PROGRAM_REVENUE";} } ::if {$Class ne ""} {::return $Class;} ::return "GENERAL"; } method account_process {Arg} { ::set Name [::sargs::get $Arg ".name"]; ::set Description [::string trim [::sargs::get $Arg ".description"]]; ::set Name [stringFilter $Name]; ::set Description [stringFilter $Description]; ::if {$Name ne ""} { ::set _accounts_have_been_processed 1; ::set Class [account_class $Arg]; ::if {$Class eq "PAYROLL"&&!$_payroll_is_installed} { ::set Class "GENERAL"; } ::if {$Class eq "PAYROLL"} { ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds"] odb_factory]; } else { ::if {$::qw::control(airtech)} { ::if {$Class eq "AR"} { ::set Class "AR/AIRTECH"; } } ::if {$_idPrefix eq "000"} { ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds"] odb_factory]; } else { ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/$Class$_slashIdPrefix.odb_deriveds"] odb_factory]; } ::if {$::qw::control(airtech)} { ::if {$Class eq "AR/AIRTECH"} { ::set Class "AR"; } } } [$Object ".folder"] odb_set "file"; [$Object ".nplclass"] odb_set $Class; [$Object ".name"] odb_set $Name; ::if {[[$Object ".line_type"] odb_get] ne "text_line"} { [$Object ".normal_balance"] odb_set [::sargs::get $Arg ".normal_balance"]; [$Object ".setup_column"] odb_set [::sargs::get $Arg ".setup_column"]; [$Object ".underline"] odb_set [::sargs::get $Arg ".setup_underline"]; } increment [::string tolower $Class]_accounts-processed; increment all_accounts-processed; ::set _account_class_array($Name) $Class; ::set Status "[::string totitle $Class] account, $Name" ::if {$Description ne ""} { ::append Status ", [::string range $Description 0 29]"; } } else { ::set Class ""; ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$Object ".folder"] odb_set "file"; [$Object ".line_type"] odb_set "text_line"; [$Object ".setup_column"] odb_set [::sargs::get $Arg ".setup_column"]; [$Object ".underline"] odb_set [::sargs::get $Arg ".setup_underline"]; increment notes-processed; ::set Status ""; } ::if {$Description ne ""} { [$Object ".description"] odb_set $Description; } ::set ReportName [::sargs::get $Arg ".report"]; ::if {$ReportName ne ""} { [$Object ".report"] odb_set [[report_get $ReportName] ".accounts"]; } ::if {$Name ne ""} { ::set Notes [::sargs::get $Arg ".notes"]; ::if {$Notes ne ""} { [$Object ".notes"] odb_set [text_filter $Notes]; increment notes-processed [text_count $Notes]; } ::set Records [::sargs::get $Arg ".records"]; ::if {$Records ne ""} { [$Object ".records"] odb_set [text_filter $Records]; increment records-processed [text_count $Records]; } ::set Import_Datum ""; ::if {[::sargs::exists $Arg ".budget"]} { ::sargs::var::set Import_Datum ".budget" [::sargs::get $Arg ".budget"]; } ::if {$Class ne "TOTAL"&&$Class ne ""} { ::sargs::var::set Import_Datum ".history" [::sargs::get $Arg ".history"]; increment history-target; } ::if {[::sargs::exists $Arg ".totals"]} { ::sargs::var::set Import_Datum ".totals" [::sargs::get $Arg ".totals"]; } ::if {$Import_Datum ne ""} { [$Object ".import_datum"] odb_set $Import_Datum; } ::if {[::sargs::exists $Arg ".errors"]} { errors_set $Object [::sargs::get $Arg ".errors"]; } } commit $Object; status $Status; batch_check_accounts; } method newviews_notes_process {} { ::if {$_notesconvert_done} {::return $this;} copyNplSetup; ::set Index [$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds.index/name_closure/posting"]; ::if {$_is_batch&&$_batch_notesconvert_account ne ""} { ::set Account [$_manager cpp_find_from_address $_batch_notesconvert_account]; ::set Ref [$Account ".odb_base"]; ::set Ref [$Index odb_next $Ref]; } else { ::set Ref [$Index odb_first]; } ::for {;} {$Ref ne ""} {::set Ref [$Index odb_next $Ref];} { ::if {$_slashIdPrefix ne ""&&[[[$Ref odb_master] odb_base] odb_id] ne $_slashIdPrefix} {::continue;} ::set AccountName [[[$Ref odb_master] ".name"] qw_get]; ::set _batch_notesconvert_account [$Ref odb_master]; processOneAccount [$Ref odb_master]; increment notesconvert-processed; batch_check_notesconvert; ::set _batch_notesconvert_account ""; } ::set _notesconvert_done 1; ::return $this; } public method processOneAccount {Src} { ::set Name [[$Src .name] qw_get]; ::if {$Name eq "BUDGET_BALANCE"} {increment notesconvert-processed -1;::return;} ::set Class [[$Src ".nplclass"] odb_get]; ::array set RecordFields {}; ::switch -- $Class { "DONOR" - "PROGRAM" {::return $this;} "DEFAULT" - "TOTAL" - "PAYROLL" - "CANADA_PAYROLL" - "USA_PAYROLL" - "GENERAL" - "BANK" {::return $this;} "AR" - "AP" {::array set RecordFields [records_fields_extract $Src $Class];} } ::array set Fields [fields_extract $Src $Class]; ::if {[::array size Fields]==0&&[::array size RecordFields]==0} {::return $this;} status "Converting notes for [[$Src .nplclass] odb_get] account $Name"; ::switch -- $Class { "DONOR" { } "AP" { ::set Address ""; ::for {::set i 1;} {$i<=8} {::incr i;} { ::set Text ""; ::if {[::info exists Fields(.address$i)]} {::set Text $Fields(.address$i);} ::append Address $Text\n; } ::set Address [::string trimright $Address]; ::set CompanyName [::lindex [::split $Address \n] 0]; ::if {$CompanyName ne ""} {[$Src ".address.company"] odb_set $CompanyName;} ::set Address [::join [::lrange [::split $Address \n] 1 end] \n]; ::if {$Address ne ""} {[$Src ".address.freeform"] odb_set $Address;} ::if {[::info exists Fields(.address.phone.freeform)]} {[$Src ".address.phone.freeform"] odb_set $Fields(.address.phone.freeform);} ::if {[::info exists Fields(.address.phone/fax.freeform)]} {[$Src ".address.phone/fax.freeform"] odb_set $Fields(.address.phone/fax.freeform);} ::switch $_purchase_tax_library { "NV1" { ::foreach FieldName { .trade_tax/1.is_charged .trade_tax/2.is_charged } { ::if {![::info exists Fields($FieldName)]} {::continue;} ::set Value [::string trim $Fields($FieldName)]; ::if {$Value eq "" || ![::string is boolean $Value]} {::continue;} ::if {$Value} {::set Value "yes";} else {::set Value "no";} [$Src $FieldName] odb_set $Value; } } "HST" { ::if {[::info exists Fields(.trade_tax/1.is_charged)]} { ::switch -- [::string index $Fields(.trade_tax/1.is_charged) 0] { "Y" {[$Src ".trade_tax/1.is_charged"] odb_set "yes";} "N" {[$Src ".trade_tax/1.is_charged"] odb_set "no";} "H" {[$Src ".trade_tax/2.is_charged"] odb_set "yes";} } } } } ::foreach FieldName { .terms.discount_days .terms.due_days .terms.discount_rate } { ::if {![::info exists Fields($FieldName)]} {::continue;} ::set Value [::string trim $Fields($FieldName)]; ::if {[::catch {::expr 0+$Value}]} {::continue;} [$Src $FieldName] odb_set $Value; } ::foreach FieldName { .trade_tax/1.registration_id .trade_tax/2.registration_id } { ::if {![::info exists Fields($FieldName)]} {::continue;} ::set Value [::string trim $Fields($FieldName)]; ::if {$Value eq ""} {::continue;} [$Src $FieldName] odb_set $Value; } ::foreach FieldSpec $_accountRecordsArray($Class) { ::set FieldName [::lindex $FieldSpec 0]; ::if {![::info exists RecordFields($FieldName)]} {::continue;} [$Src $FieldName] odb_set $RecordFields($FieldName); } ::set Name ""; ::foreach FieldName { .address.name.salutation .address.name.first .address.name.middle .address.name.last } { ::if {![::info exists RecordFields($FieldName)]} {::continue;} ::if {$Name ne ""} {::append Name " ";} ::append Name $RecordFields($FieldName); } ::if {$Name ne ""} {[$Src ".address.name.freeform"] odb_set $Name;} } "AR" { ::set Address ""; ::for {::set i 1;} {$i<=8} {::incr i;} { ::set Text ""; ::if {[::info exists Fields(.address$i)]} {::set Text $Fields(.address$i);} ::append Address $Text\n; } ::set Address [::string trimright $Address]; ::set CompanyName [::lindex [::split $Address \n] 0]; ::if {$CompanyName ne ""} {[$Src ".address.company"] odb_set $CompanyName;} ::set Address [::join [::lrange [::split $Address \n] 1 end] \n]; ::if {$Address ne ""} {[$Src ".address.freeform"] odb_set $Address;} ::set Address ""; ::for {::set i 1;} {$i<=8} {::incr i;} { ::set Text ""; ::if {[::info exists Fields(.shipAddress$i)]} {::set Text $Fields(.shipAddress$i);} ::append Address $Text\n; } ::set Address [::string trimright $Address]; ::set CompanyName [::lindex [::split $Address \n] 0]; ::if {$CompanyName ne ""} {[$Src ".address/shipping.company"] odb_set $CompanyName;} ::set Address [::join [::lrange [::split $Address \n] 1 end] \n]; ::if {$Address ne ""} {[$Src ".address/shipping.freeform"] odb_set $Address;} ::if {[::info exists Fields(.address.phone.freeform)]} {[$Src ".address.phone.freeform"] odb_set $Fields(.address.phone.freeform);} ::if {[::info exists Fields(.address.phone/fax.freeform)]} {[$Src ".address.phone/fax.freeform"] odb_set $Fields(.address.phone/fax.freeform);} ::switch $_sales_tax_library { "NV1" { ::if {[::info exists Fields(.trade_tax/1.is_charged)]} { ::switch -- [::string index $Fields(.trade_tax/1.is_charged) 0] { "T" {[$Src ".trade_tax/1.is_charged"] odb_set "yes";} "X" {[$Src ".trade_tax/1.is_charged"] odb_set "no";} } } ::if {[::info exists Fields(.trade_tax/2.is_charged)]} { ::switch -- $Fields(.trade_tax/2.is_charged) { "T" {[$Src ".trade_tax/2.is_charged"] odb_set "yes";} "X" {[$Src ".trade_tax/2.is_charged"] odb_set "no";} } } } "HST" { ::if {[::info exists Fields(.trade_tax/1.is_charged)]} { ::switch -- [::string index $Fields(.trade_tax/1.is_charged) 0] { "T" {[$Src ".trade_tax/1.is_charged"] odb_set "yes";} "X" {[$Src ".trade_tax/1.is_charged"] odb_set "no";} "H" {[$Src ".trade_tax/2.is_charged"] odb_set "yes";} } } ::if {[::info exists Fields(.trade_tax/2.is_charged)]} { ::switch -- $Fields(.trade_tax/2.is_charged) { "T" {[$Src ".trade_tax/2.is_charged"] odb_set "yes";} "X" {[$Src ".trade_tax/2.is_charged"] odb_set "no";} } } } } ::foreach FieldName { .terms.discount_days .terms.discount_rate .terms.due_days .terms.interest_rate } { ::if {![::info exists Fields($FieldName)]} {::continue;} ::set Value [::string trim $Fields($FieldName)]; ::if {[::catch {::expr 0+$Value}]} {::continue;} [$Src $FieldName] odb_set $Value; } ::foreach FieldSpec $_accountRecordsArray($Class) { ::set FieldName [::lindex $FieldSpec 0]; ::if {![::info exists RecordFields($FieldName)]} {::continue;} [$Src $FieldName] odb_set $RecordFields($FieldName); } ::set Name ""; ::foreach FieldName { .address.name.salutation .address.name.first .address.name.middle .address.name.last } { ::if {![::info exists RecordFields($FieldName)]} {::continue;} ::if {$Name ne ""} {::append Name " ";} ::append Name $RecordFields($FieldName); } ::if {$Name ne ""} {[$Src ".address.name.freeform"] odb_set $Name;} } "EXPENSE" - "INVENTORY" { ::switch $_sales_tax_library { "NV1" { ::if {[::info exists Fields(.trade_tax/1.expense_or_refund_account)]} { ::if {[accountExists $Fields(.trade_tax/1.expense_or_refund_account)]} { [$Src ".trade_tax/1.expense_or_refund_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/1.expense_or_refund_account)]; } } ::if {[::info exists Fields(.trade_tax/1.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/1.rate) -dest $Src -name ".trade_tax/1";} ::if {[::info exists Fields(.trade_tax/2.expense_or_refund_account)]} { ::if {[accountExists $Fields(.trade_tax/2.expense_or_refund_account)]} { [$Src ".trade_tax/2.expense_or_refund_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/2.expense_or_refund_account)]; } } ::if {[::info exists Fields(.trade_tax/2.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/2.rate) -dest $Src -name ".trade_tax/2";} } "HST" { ::if {[::info exists Fields(.trade_tax/1.expense_or_refund_account)]} { ::if {[accountExists $Fields(.trade_tax/1.expense_or_refund_account)]} { [$Src ".trade_tax/1.expense_or_refund_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/1.expense_or_refund_account)]; [$Src ".trade_tax/2.expense_or_refund_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/1.expense_or_refund_account)]; } } ::if {[::info exists Fields(.trade_tax/1.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/1.rate) -dest $Src -name ".trade_tax/1";} ::if {[::info exists Fields(.trade_tax/3.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/3.rate) -dest $Src -name ".trade_tax/2";} } } } "CGS" { } "SALES" { ::switch $_sales_tax_library { "NV1" { ::if {[::info exists Fields(.trade_tax/1.payable_account)]} { ::if {[accountExists $Fields(.trade_tax/1.payable_account)]} { [$Src ".trade_tax/1.payable_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/1.payable_account)]; } } ::if {[::info exists Fields(.trade_tax/1.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/1.rate) -dest $Src -name ".trade_tax/1";} ::if {[::info exists Fields(.trade_tax/2.payable_account)]} { ::if {[accountExists $Fields(.trade_tax/2.payable_account)]} { [$Src ".trade_tax/2.payable_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/2.payable_account)]; } } ::if {[::info exists Fields(.trade_tax/2.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/2.rate) -dest $Src -name ".trade_tax/2";} } "HST" { ::if {[::info exists Fields(.trade_tax/1.payable_account)]} { ::if {[accountExists $Fields(.trade_tax/1.payable_account)]} { [$Src ".trade_tax/1.payable_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/1.payable_account)]; [$Src ".trade_tax/2.payable_account"] odb_set [accountOdbAddressFromName $Fields(.trade_tax/1.payable_account)]; } } ::if {[::info exists Fields(.trade_tax/1.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/1.rate) -dest $Src -name ".trade_tax/1";} ::if {[::info exists Fields(.trade_tax/3.rate)]} {setTaxStatusAndRate -src $Fields(.trade_tax/3.rate) -dest $Src -name ".trade_tax/2";} } } ::if {[::info exists Fields(.price)]} { ::set Price [::string trim $Fields(.price)]; ::if {$Price ne ""&&[::string is double $Price]} { [$Src ".price"] odb_set $Price; } } } default {import_error "CONVERT_NV1_TO_NV2 didn't recognize Src Class==$Class for Src odb_path==[$Src odb_path]";} } commit $Src; ::return $this; } public method books_have_been_compressed {} { ::if {![::qw::date::is_null $_yearly_res_begin_date]} {::return 1;} ::if {![::qw::date::is_null $_monthly_res_begin_date]} {::return 1;} ::if {![::qw::date::is_null $_daily_res_begin_date]} {::return 1;} ::if {![::qw::date::is_null $_full_res_begin_date]} {::return 1;} ::return 0; } public method books_have_been_purged {} { ::set Fields [[[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/ODDS_AND_ENDS"] ".fields"] odb_get]; ::if {[::sargs::get $Fields ".purge_audit_sequence_number"]!=0} {::return 1;} ::return 0; } public method budgets_process {} { ::if {$_table(budgets-processed)==$_table(budgets-target)} { ::return $this; } ::set AccountsIndex [$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds.index/name_closure/posting"]; ::set Journal [[[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" BUDGET] odb_master]; ::set BalanceAccount [[[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" BUDGET_BALANCE] odb_master]; ::if {$_is_batch&&$_batch_budget_account ne ""} { ::set TAccount [$_manager cpp_find_from_address $_batch_budget_account]; ::set Ref [$TAccount ".odb_base"]; ::set Ref [$AccountsIndex odb_next $Ref]; } else { ::set Ref [$AccountsIndex odb_first]; } ::for {;} {$Ref ne ""} {::set Ref [$AccountsIndex odb_next $Ref];} { abort_check; ::if {$_slashIdPrefix ne ""&&[[[$Ref odb_master] odb_base] odb_id] ne $_slashIdPrefix} { ::continue; } ::set Account [$Ref odb_master]; ::set Import_Datum [[$Account ".import_datum"] odb_get]; ::set Name [[$Account ".name"] odb_get]; ::set AccountId [$Account odb_id]; status "Checking account $Name for budgets"; ::if {![::sargs::exists $Import_Datum ".budget"]} { ::continue; } ::set Budgets [::sargs::get $Import_Datum ".budget"]; ::set NormalBalance [$Account normal_balance_get]; ::set _batch_budget_account [$Ref odb_master]; ::foreach Budget $Budgets { ::set Amount [::sargs::get $Budget ".amount"]; increment budgets-processed; ::if {$Amount==0.0} {::continue;} ::set BeginDate [::sargs::get $Budget ".period.begin"]; ::set EndDate [::sargs::get $Budget ".period.end"]; ::set Period "[::qw::date::format $BeginDate {%d %b %Y}]-[::qw::date::format $EndDate {%d %b %Y}]"; status "Setting budget for account $Name, period $Period, amount $Amount"; ::set Transaction [[$Journal ".transactions.index/date"] odb_find_key .tag budget .date $EndDate]; ::if {$Transaction eq ""} { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/GENERAL.odb_deriveds"] odb_factory]; [$Transaction ".folder"] odb_set "file"; [$Transaction ".journal"] odb_set [$Journal ".transactions"]; [$Transaction ".date"] odb_set $EndDate; ;#// some really interesting problems without this??? [$Transaction ".description"] odb_set "Budget"; $Transaction odb_commit; } else { ::set Transaction [$Transaction odb_master]; } ::if {$NormalBalance eq "debit"} { ::set Item [[$Transaction ".odb_deriveds.index/debit_account"] odb_find_key .account_id $AccountId]; ::if {$Item eq ""} { ::set Item [[$Transaction ".odb_deriveds"] odb_factory]; [$Item ".folder"] odb_set "file"; } else { ::qw::throw "Unexpected debit budget transaction for account $Name on date $EndDate."; ::set Item [$Item odb_master]; } [$Item ".description"] odb_set "Budget"; [$Item ".posting/debit.account"] odb_set [$Account ".postings"]; [$Item ".posting/debit.amount"] odb_set $Amount; [$Item ".posting/credit.account"] odb_set [$BalanceAccount ".postings"]; } else { ::set Item [[$Transaction ".odb_deriveds.index/credit_account"] odb_find_key .account_id $AccountId]; ::if {$Item eq ""} { ::set Item [[$Transaction ".odb_deriveds"] odb_factory]; [$Item ".folder"] odb_set "file"; } else { ::qw::throw "Unexpected credit budget transaction for account $Name on date $EndDate."; ::set Item [$Item odb_master]; } [$Item ".description"] odb_set "Budget"; [$Item ".posting/credit.account"] odb_set [$Account ".postings"]; [$Item ".posting/credit.amount"] odb_set [::qw::number::var::negative Amount]; [$Item ".posting/debit.account"] odb_set [$BalanceAccount ".postings"]; } ::set Data [$Item qw_structure -fields 1 -kids 1 -command qw_get]; ::sargs::var::+= Data [$Item qw_structure -fields 1 -kids 1 -command odb_get]; $Item odb_commit; } batch_check_budget; } } method purgedHistoryJournalGet {} { ::set Journal [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT.odb_deriveds.index/name"] odb_find_key ".name" "NV1_PURGED_HISTORY"]; ::if {$Journal ne ""} { ::return [$Journal odb_master]; } ::set Journal [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT.odb_deriveds"] odb_factory -odb_id "/NV1_PURGED_HISTORY"]; [$Journal ".name"] odb_set "NV1_PURGED_HISTORY"; [$Journal ".description"] odb_set "NV1 Purged History"; [$Journal ".tags"] odb_set "financial"; commit $Journal; ::return $Journal; } method purgedBalanceAccountGet {} { ::set HeaderAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "NV1_PURGED_HISTORY"]; ::if {$HeaderAccount ne ""} { ::return [$HeaderAccount odb_master]; } ::set HeaderAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/NV1_PURGED_HISTORY"]; [$HeaderAccount ".folder"] odb_set "file"; [$HeaderAccount ".normal_balance"] odb_set "debit"; [$HeaderAccount ".setup_column"] odb_set "1"; [$HeaderAccount ".name"] odb_set "NV1_PURGED_HISTORY"; [$HeaderAccount ".description"] odb_set "NV1 Purged History Balancing Account"; commit $HeaderAccount; ::return $HeaderAccount; } method purgedHistoryTransactionGet {PeriodBegin PeriodEnd} { ::set Journal [purgedHistoryJournalGet]; ::set Header [[$Journal ".transactions.index/date"] odb_find_key .tag financial .date $PeriodEnd]; ::if {$Header ne ""} { ::return [$Header odb_master]; } ::set Header [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/GENERAL.odb_deriveds"] odb_factory]; [$Header ".folder"] odb_set "file"; [$Header ".journal"] odb_set [$Journal ".transactions"]; [$Header ".date"] odb_set $PeriodEnd; [$Header ".description"] odb_set "NV1 Purged History [::qw::date::format $PeriodBegin {%d %b %Y}] - [::qw::date::format $PeriodEnd {%d %b %Y}] "; [$Header ".posting/debit.account"] odb_set [[purgedBalanceAccountGet] ".postings"]; commit $Header; ::return $Header } method check_books_history {} { ::set HistoryPeriodsList ""; ::if {$_current_fiscal_year_end eq ""} { ::set OddsAndEndsFields [[[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/ODDS_AND_ENDS"] ".fields"] odb_get]; ::if {[::sargs::get $OddsAndEndsFields ".current_fiscal_year_end"] eq ""} {::return;} ::set _current_fiscal_year_end [::sargs::get $OddsAndEndsFields ".current_fiscal_year_end"]; } ::set Begin ""; ::set End [::qw::date::add $_current_fiscal_year_end year -10]; ::set End [::qw::date::set $End day [::qw::date::get $End "days_in_month"]]; ::set End [::string range $End 0 7]; ::lappend HistoryPeriodsList [::list ".begin" $Begin ".end" $End]; ::for {::set i 0} {$i<8} {::incr i;} { ::set End [::qw::date::add $End year 1]; ::set End [::qw::date::set $End day [::qw::date::get $End "days_in_month"]]; ::set Begin [::qw::date::add $End day 1]; ::set Begin [::qw::date::add $Begin year -1]; ::set Begin [::string range $Begin 0 7]; ::set End [::string range $End 0 7]; ::lappend HistoryPeriodsList [::list ".begin" $Begin ".end" $End]; } ::for {::set i 0} {$i<36} {::incr i;} { ::set End [::qw::date::add $End month 1]; ::set End [::qw::date::set $End day [::qw::date::get $End "days_in_month"]]; ::set Begin [::qw::date::set $End day 1]; ::set Begin [::string range $Begin 0 7]; ::set End [::string range $End 0 7]; ::lappend HistoryPeriodsList [::list ".begin" $Begin ".end" $End]; } ::array set TransactionArray {}; ::set Range_debit [::qw::odb::factory range]; ::set Range_credit [::qw::odb::factory range]; ::set BooksWerePurged [::expr [books_have_been_purged]||[books_have_been_compressed]]; ::set AccountsIndex [$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds.index/name_closure/posting"]; ::if {$_is_batch&&$_batch_history_account ne ""} { ::set Ref [$_manager cpp_find_from_address $_batch_history_account]; ::set Ref [$Ref ".odb_base"]; ::set Ref [$AccountsIndex odb_next $Ref]; } else { ::set Ref [$AccountsIndex odb_first]; } ::for {;} {$Ref ne ""} {::set Ref [$AccountsIndex odb_next $Ref];} { ::set Account [$Ref odb_master]; ::set Name [[$Account ".name"] odb_get]; ::if {$Name eq "JOURNAL_ERRORS"||[::string first "~" $Name]==0} { ::if {[books_have_been_purged]} { status "*** WARNING *** NV1 Accrual Payroll convert detected purging... contact Q.W. Page Technical Support."; } increment history-processed; ::continue; } ::if {$_slashIdPrefix ne ""&&[[[$Ref odb_master] odb_base] odb_id] ne $_slashIdPrefix} { ::continue; } ::set Import_Datum [[$Account ".import_datum"] odb_get]; ::if {![::sargs::exists $Import_Datum ".history"]} { ::continue; } ::if {[::sargs::exists $Import_Datum ".history_ignore"]} { increment history-processed; ::continue; #// An employee GT account which we know will not have all the DOS postings in it. } ::set _batch_history_account $Account; abort_check; $Range_debit cpp_configure -index [$Account ".postings.index/date/debit"]; $Range_credit cpp_configure -index [$Account ".postings.index/date/credit"]; ::if {$BooksWerePurged} { ::set Status "Recording purged history, $Name"; } else { ::set Status "Checking history, $Name"; } status $Status; ::foreach Type {debit credit} { ::foreach BooksPeriod $HistoryPeriodsList { abort_check; ::set BooksPeriodBegin [::sargs::get $BooksPeriod ".begin"]; ::set BooksPeriodEnd [::sargs::get $BooksPeriod ".end"]; ::set AccountHistoryAmount ""; ::foreach AccountHistoryItem [::sargs::get $Import_Datum ".history"] { ::set Begin [::sargs::get $AccountHistoryItem ".period.begin"]; ::set End [::sargs::get $AccountHistoryItem ".period.end"]; ::if {$Begin ne ""} { ::if {[::qw::date::difference $Begin $End "month"]==0} { ::if {[::qw::date::difference $_monthly_res_begin_date $Begin "day"]>0} { ::continue; } } } ::if {$Begin ne [::sargs::get $BooksPeriod ".begin"]} {::continue;} ::if {$End ne [::sargs::get $BooksPeriod ".end"]} {::continue;} ::set AccountHistoryAmount [::sargs::get $AccountHistoryItem ".amount.$Type"]; ::break; } ::if {$AccountHistoryAmount eq ""} {::set AccountHistoryAmount 0.0;} ::set Difference 0.0; ::switch -- $Type { debit { ::if {$BooksPeriodBegin ne ""} { $Range_debit cpp_configure -begin [::list .tag financial .date $BooksPeriodBegin] -end [::list .tag financial .date [::qw::date::extend_end $BooksPeriodEnd]]; } else { $Range_debit cpp_configure -begin [::list .tag financial] -end [::list .tag financial .date [::qw::date::extend_end $BooksPeriodEnd]]; } ::set LedgerAmount [$Range_debit odb_total ".path .amount"]; ::set Difference [::expr {$LedgerAmount-$AccountHistoryAmount}]; } credit { ::if {$BooksPeriodBegin ne ""} { $Range_credit cpp_configure -begin [::list .tag financial .date $BooksPeriodBegin] -end [::list .tag financial .date [::qw::date::extend_end $BooksPeriodEnd]]; } else { $Range_credit cpp_configure -begin [::list .tag financial] -end [::list .tag financial .date [::qw::date::extend_end $BooksPeriodEnd]]; } ::set LedgerAmount [$Range_credit odb_total ".path .amount"]; ::set Difference [::expr {$LedgerAmount-$AccountHistoryAmount}]; } open { } closed { } } ::if {$Difference==0.0} { ::continue; } ::set PeriodText "[::qw::date::format $BooksPeriodBegin {%d %b %Y}]-[::qw::date::format $BooksPeriodEnd {%d %b %Y}]"; ::if {$BooksWerePurged} { status "$Status $PeriodText $Type [::expr abs($Difference)]"; ::if {[::info exists TransactionArray($BooksPeriodEnd)]} { ::set Header $TransactionArray($BooksPeriodEnd); } else { ::set Header [purgedHistoryTransactionGet $BooksPeriodBegin $BooksPeriodEnd]; ::set TransactionArray($BooksPeriodEnd) $Header; } ::set Transaction [[$Header ".odb_deriveds"] odb_factory]; [$Transaction ".description"] odb_set "NV1 Purged History [::qw::date::format $BooksPeriodBegin {%d %b %Y}] - [::qw::date::format $BooksPeriodEnd {%d %b %Y}] "; [$Transaction ".posting/credit.account"] odb_set [$Account ".postings"]; [$Transaction ".posting/credit.amount"] odb_set [::qw::number::negative $Difference]; [$Transaction ".posting/credit.reconcile"] odb_set $BooksPeriodEnd; commit $Transaction; ::if {[::string first "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL" [$Account odb_path]]==0} { ::if {[::string first "~" [[$Account ".name"] odb_get]]>0} { ::set EqualName [::string map "~ =" [[$Account ".name"] odb_get]]; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $EqualName]; ::if {$Reference eq ""} { ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Object ".folder"] odb_set "file"; [$Object ".nplclass"] odb_set "PAYROLL"; [$Object ".name"] odb_set $EqualName; [$Object ".description"] odb_set [[$Account ".description"] odb_get]; [$Object ".normal_balance"] odb_set "credit"; [$Object ".setup_column"] odb_set [[$Account ".setup_column"] odb_get]; [$Object ".underline"] odb_set [[$Account ".underline"] odb_get]; [$Object ".report"] odb_set [[$Account ".report"] odb_get]; [$Object ".employee"] odb_set [[$Account ".employee"] odb_get]; $Object odb_commit; ::set _account_class_array($EqualName) "PAYROLL"; ::set AW_maybe ""; ::set Employee [[[$Account ".employee"] odb_get] odb_master]; ::set Id [[$Employee ".employee_id"] odb_get]; ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-AW"]; ::if {$AW_maybe eq ""} { ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.AW"]; } employee_accounts_cleanup_accrual $Employee $Object $AW_maybe; ::set Reference $Object; } ::if {$Reference ne ""} { ::set Transaction [[$Header ".odb_deriveds"] odb_factory]; [$Transaction ".description"] odb_set "NV1 Purged History [::qw::date::format $BooksPeriodBegin {%d %b %Y}] - [::qw::date::format $BooksPeriodEnd {%d %b %Y}] "; [$Transaction ".posting/credit.account"] odb_set [[$Reference odb_master] ".postings"]; [$Transaction ".posting/credit.amount"] odb_set $Difference; [$Transaction ".posting/credit.reconcile"] odb_set $BooksPeriodEnd; commit $Transaction; } } } } else { ::set Error "account: $Name"; ::append Error " period:[::qw::date::format $BooksPeriodBegin {%b %d %Y}] - [::qw::date::format $BooksPeriodEnd {%b %d %Y}]"; ::append Error " type: $Type" ::append Error " history amount: $AccountHistoryAmount"; ::append Error " ledger amount: $LedgerAmount"; ::append Error " difference: $Difference"; ::lappend _history_error_list $Error; status "$Status $PeriodText $Type error: $Difference"; } } } increment history-processed; batch_check_history; } ::set _batch_history_account ""; ::if {!$BooksWerePurged} { ::set _history_errors [::llength $_history_error_list]; ::if {$_history_errors} { ::set Import_Datum [[[$_manager "/OBJECT/NEWVIEWS/ACCOUNT"] ".import_datum"] odb_get]; ::sargs::var::set Import_Datum ".history_errors" [::join $_history_error_list \n]; [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT"] ".import_datum"] odb_set $Import_Datum; commit [$_manager "/OBJECT/NEWVIEWS/ACCOUNT"]; } } $Range_debit cpp_destroy; $Range_credit cpp_destroy; } public method date_normalize {Src} { ::if {$Src eq ""} {return "";} ::set Src [::qw::date::set $Src hour 0]; ::set Src [::qw::date::set $Src minute 0]; ::set Src [::qw::date::set $Src second 0]; ::return $Src; } method account_count {Arg} { ::set Name [::sargs::get $Arg ".name"]; ::if {$Name eq ""} { increment notes-target; ::return $this; } ::set Class [account_class $Arg]; increment [::string tolower $Class]_accounts-target; ::if {$Class ne "TOTAL"} {increment notesconvert-target;} increment all_accounts-target; increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; increment budgets-target [::llength [::sargs::get $Arg ".budget"]]; ::set Totalto1 [::sargs::get $Arg ".totals.totalto1"]; ::set Totalto2 [::sargs::get $Arg ".totals.totalto2"]; ::set Totals ""; ::if {$Totalto1 ne ""} {increment totaltos-target;} ::if {$Totalto2 ne ""} {increment totaltos-target;} ::set _account_totalto_array($Name) [::list $Totalto1 $Totalto2]; ::return $this; } method totaltos_process {} { ::if {$_totaltos_have_been_processed} {::return $this;} ::if {!$_table(totaltos-doit)} {::return $this;} ::set SearchId [::array startsearch _account_totalto_array]; ::set AccountsProcessed ""; ::set Limit [::expr $_table(totaltos-target)-$_table(totaltos-processed)]; ::if {$_is_batch&&$_batch_totalto_items_per_batch<$Limit} {::set Limit $_batch_totalto_items_per_batch;} ::set Done 0; ::while {$Done<$Limit} { ::set AccountName [::array nextelement _account_totalto_array $SearchId]; ::if {$AccountName eq ""} {::break;} ::lappend AccountsProcessed $AccountName; ::foreach {Totalto1 Totalto2} $_account_totalto_array($AccountName) {;} ::if {$Totalto1 eq "" && $Totalto2 eq ""} {::continue;} ::set KidAccount [account_get $AccountName]; ::if {$Totalto1 ne ""} { status "Totaling $AccountName to $Totalto1"; ::set ParentAccount [account_get $Totalto1]; [$KidAccount ".total.parent1"] odb_set [$ParentAccount ".total.kids"]; increment totaltos-processed; ::incr Done; } ::if {$Totalto2 ne ""} { status "Totaling $AccountName to $Totalto2"; ::set ParentAccount [account_get $Totalto2]; [$KidAccount ".total.parent2"] odb_set [$ParentAccount ".total.kids"]; increment totaltos-processed; ::incr Done; } commit $KidAccount; } ::array donesearch _account_totalto_array $SearchId; ::foreach AccountName $AccountsProcessed { ::unset _account_totalto_array($AccountName); } ::if {[::array size _account_totalto_array]==0} { ::set _totaltos_have_been_processed 1; ::if {$_is_batch} {batch_complete}; } batch_check_totaltos; ::return $this; } method dump_books_total_to_information {} { ::set PostingAccounts 0; ::set TotalAccounts 0; ::set Totaltos 0; ::set AverageTotaltos 0; ::set MaxTotaltos 0; ::set WorstAccount ""; ::set WorstAccountList ""; ::set Index [$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds.index/odb_path_backward"]; ::for {::set Reference [$Index odb_first];} {$Reference ne ""} {::set Reference [$Index odb_next $Reference];} { ::set Account [$Reference odb_master]; ::set Name [[$Account ".name"] odb_get]; status "Logging totaling stats: $Name"; ::if {[[$Account ".total.kids"] odb_items]>0} { ::incr TotalAccounts; } else { ::incr PostingAccounts; ::set Closure [[$Account ".postings"] odb_closure]; ::set Totals [::llength $Closure]; ::set Totaltos [::expr {$Totaltos+$Totals}]; ::if {$Totals>$MaxTotaltos} { ::set MaxTotaltos $Totals; ::set WorstAccount $Name; ::set WorstAccountList $Closure; } ::set AverageTotaltos [::expr {double($Totaltos)/$PostingAccounts}]; } } ::set Handle [::open $_exported_path.totalsinfo w+]; ::foreach Stat {PostingAccounts TotalAccounts Totaltos AverageTotaltos MaxTotaltos} { ::puts $Handle "$Stat\t[::set $Stat]"; } ::puts $Handle "Deepest total-to account is: $WorstAccount"; ::puts $Handle "Deepest total-to closure list is:"; ::foreach Item $WorstAccountList { ::puts $Handle "\t[[$Item odb_master] odb_path_readable]"; } ::close $Handle; ::return $this; } method journalentry_preprocess {Arg} { ::set ComplexCount 0; ::set SimpleCount 0; ::set ComplexItems ""; ::set SimpleItems ""; ::set DAccount ""; ::set CAccount ""; ::set DAmount 0.0; ::foreach JournalItem [::sargs::get $Arg .items] { ::if {[::sargs::exists $JournalItem ".distributions"]} { ::incr ComplexCount; ::lappend ComplexItems $JournalItem; } else { ::if {[::sargs::exists $JournalItem ".debit"]} { ::set DAccount [::sargs::get $JournalItem ".debit.account"]; ::set DAmount [::expr $DAmount+[::qw::number::scan [::sargs::get $JournalItem ".debit.amount"]]]; ::incr SimpleCount; ::lappend SimpleItems $JournalItem; ::continue; } ::if {[::sargs::exists $JournalItem ".credit"]} { ::set CAccount [::sargs::get $JournalItem ".credit.account"]; ::incr SimpleCount; ::lappend SimpleItems $JournalItem; ::continue; } } } ::set TotalCount [::expr $ComplexCount+$SimpleCount]; ::set Description "Journal entry"; ::if {$TotalCount==2} { ::if {$SimpleCount==2} { ::if {$DAccount ne "" && $DAccount eq $CAccount && $DAmount!=0.0} { ::set OriginalItems [::sargs::get $Arg ".items"]; ::sargs::var::unset Arg ".items"; ::set Notes ""; ::set Records ""; ::set Items ""; ::foreach Item $OriginalItems { ::if {[::sargs::exists $Item ".notes"]} { ::append Notes [::sargs::get $Item ".notes"]; ::sargs::var::unset Item ".notes"; } ::if {[::sargs::exists $Item ".records"]} { ::append Records [::sargs::get $Item ".records"]; ::sargs::var::unset Item ".records"; } ::lappend Items $Item; } ::set Item ""; ::sargs::var::set Item ".description" [::sargs::get [::lindex $Items 0] ".description"]; ::if {$Notes ne ""} {::sargs::var::set Item ".notes" $Notes;} ::if {$Records ne ""} {::sargs::var::set Item ".records" $Records;} ::sargs::var::set Item ".distributions" $Items; ::set Items ""; ::sargs::var::set Arg ".items" [::lappend $Items $Item]; ::return [journalentry_preprocess $Arg]; } ::set Description1 [::sargs::get [::lindex $SimpleItems 0] .description]; ::set Description2 [::sargs::get [::lindex $SimpleItems 1] .description]; ::if {$Description1 ne ""} { ::set Description $Description1; ::if {$Description2 ne ""} { ::if {$Description1 ne $Description2} { ::append Description " - $Description2"; } } } else { ::if {$Description2 ne ""} { ::set Description $Description2; } } } ::if {$SimpleCount==1} { ::if {[::sargs::exists [::lindex $SimpleItems 0] ".description"]} { ::set Description [::sargs::get [::lindex $SimpleItems 0] ".description"]; } ::sargs::var::set Arg .items [::list [::lindex $SimpleItems 0] [::lindex $ComplexItems 0]]; } } ::sargs::var::set Arg .description $Description; ::if {$::QW::NEWVIEWS::IMPORTER::journal_experiment} { ::sargs::var::set Arg .simplecount $SimpleCount; ::sargs::var::set Arg .complexcount $ComplexCount; ::return [payroll_journalentry_preprocess $Arg]; } ::set HeaderItem ""; ::set Items $SimpleItems; ::set SimpleItems ""; ::foreach Item $Items { ::if {$HeaderItem ne ""} { ::lappend SimpleItems $Item; ::continue; } ::if {[::sargs::exists $Item ".debit.account"]||[::sargs::exists $Item ".credit.account"]} { ::set HeaderItem $Item; } ::if {$HeaderItem eq ""} { ::lappend SimpleItems $Item; } } ::if {$HeaderItem eq ""} { ::set Items $ComplexItems; ::set ComplexItems ""; ::foreach Item $Items { ::if {$HeaderItem ne ""} { ::lappend ComplexItems $Item; ::continue; } ::set Distributions [::sargs::get $Item ".distributions"]; ::sargs::var::set Item ".distributions" ""; ::foreach DistributionItem $Distributions { ::if {$HeaderItem ne ""} { ::set TempDistributions [::sargs::get $Item ".distributions"]; ::lappend TempDistributions $DistributionItem; ::sargs::var::set Item ".distributions" $TempDistributions; ::continue; } ::foreach PostingSign {debit credit} { ::if {![::sargs::exists $DistributionItem ".$PostingSign"]} {::continue;} ::set Posting [::sargs::get $DistributionItem ".$PostingSign"]; ::if {[::sargs::exists $Posting ".account"]} { ::set HeaderItem $DistributionItem; ::set DistributionItem ""; ::foreach Name {notes records reconcile} { ::if {[::sargs::exists $Item ".$Name"]} { ::sargs::var::set HeaderItemArray ".$Name" [::sargs::get $Item ".$Name"]; ::set Item [::sargs::unset $Item ".$Name"]; } } } } ::if {$DistributionItem ne ""} { ::set TempDistributions [::sargs::get $Item ".distributions"]; ::lappend TempDistributions $DistributionItem; ::sargs::var::set Item ".distributions" $TempDistributions; } } ::lappend ComplexItems $Item; } ::if {$HeaderItem ne ""} { ::incr SimpleCount; } } ::if {$HeaderItem ne ""} { ::set SimpleItems [::linsert $SimpleItems 0 $HeaderItem]; } ::set HeaderSign ""; ::foreach Item $SimpleItems { ::foreach PostingSign {debit credit} { ::if {![::sargs::exists $Item ".$PostingSign"]} {::continue;} ::set Posting [::sargs::get $Item ".$PostingSign"]; ::if {[::sargs::exists $Posting ".amount"]} { ::set Amount [::sargs::get $Posting ".amount"]; ::if {$Amount>0} {::set HeaderSign "debit";} ::if {$Amount<0} {::set HeaderSign "credit";} } ::if {$HeaderSign ne ""} {::break;} } ::if {$HeaderSign ne ""} {::break;} } ::if {$HeaderSign eq ""} { ::foreach Item $ComplexItems { ::foreach Distribution [::sargs::get $Item ".distributions"] { ::foreach PostingSign {debit credit} { ::if {![::sargs::exists $Distribution ".$PostingSign"]} {::continue;} ::set Posting [::sargs::get $Distribution ".$PostingSign"]; ::if {[::sargs::exists $Posting ".amount"]} { ::set Amount [::sargs::get $Posting ".amount"]; ::if {$Amount>0} {::set HeaderSign "debit";} ::if {$Amount<0} {::set HeaderSign "credit";} } ::if {$HeaderSign ne ""} {::break;} } ::if {$HeaderSign ne ""} {::break;} } ::if {$HeaderSign ne ""} {::break;} } } ::if {$HeaderSign eq ""} {::set HeaderSign "debit";} ::if {$HeaderSign eq "debit"} { ::set ItemSign "credit" } else { ::set ItemSign "debit" } ::set HeaderIsSetFlag 0; ::set Items $SimpleItems; ::set SimpleItems ""; ::foreach Item $Items { ::if {$HeaderIsSetFlag} { ::if {[::sargs::exists $Item ".$HeaderSign"]} { ::sargs::var::set Item ".$ItemSign" [::sargs::get $Item ".$HeaderSign"]; ::set Item [::sargs::unset $Item ".$HeaderSign"]; } } else { ::if {[::sargs::exists $Item ".$ItemSign"]} { ::sargs::var::set Item ".$HeaderSign" [::sargs::get $Item ".$ItemSign"]; ::set Item [::sargs::unset $Item ".$ItemSign"]; ::set HeaderIsSetFlag 1; } else { ::if {[::sargs::exists $Item ".$HeaderSign"]} { ::set HeaderIsSetFlag 1; } } } ::lappend SimpleItems $Item; } ::set Items $ComplexItems; ::set ComplexItems ""; ::foreach Item $Items { ::set Distributions [::sargs::get $Item ".distributions"]; ::set NewDistributions "" ::foreach Distribution $Distributions { ::if {[::sargs::exists $Distribution ".$HeaderSign"]} { ::sargs::var::set Distribution ".$ItemSign" [::sargs::get $Distribution ".$HeaderSign"]; ::set Distribution [::sargs::unset $Distribution ".$HeaderSign"]; } ::lappend NewDistributions $Distribution; } ::sargs::var::set Item ".distributions" $NewDistributions; ::lappend ComplexItems $Item; } ::sargs::var::set Arg .sign $HeaderSign; ::unset HeaderSign; ::unset ItemSign; ::sargs::var::set Arg .simplecount $SimpleCount; ::sargs::var::set Arg .complexcount $ComplexCount; ::set Items ""; ::if {$SimpleCount==1} { ::set Items $SimpleItems; } else { ::foreach Item $SimpleItems { ::lappend Items $Item; } } ::foreach Item $ComplexItems { ::lappend Items $Item; } ::sargs::var::set Arg ".items" $Items; ::set Result [payroll_journalentry_preprocess $Arg]; ::return $Result; } method payroll_journalentry_preprocess {Arg} { ::set SavedArg $Arg; ::set IsPayrollTransaction 0; ::sargs::var::set SavedArg .isPayrollTransaction $IsPayrollTransaction; ::if {$_import_action eq "count"} {::return $SavedArg;} ::if {!$_payroll_is_installed} {::return $SavedArg;} ::set JournalItems [::sargs::get $Arg .items]; ::if {[::llength $JournalItems]>2} {::return $SavedArg;} ::set EmployeeCount 0; ::set CurrentEmployee ""; ::set NewJournalItems ""; ::set DistributionsCount 0; ::foreach JournalItem $JournalItems { ::if {![::sargs::exists $JournalItem ".distributions"]} { ::lappend NewJournalItems $JournalItem; ::continue; } ::set NewDistributionItems ""; ::foreach Distribution [::sargs::get $JournalItem ".distributions"] { ::foreach Posting {debit credit} { ::if {![::sargs::exists $Distribution ".$Posting.account"]} {::continue;} ::set AccountName [::sargs::get $Distribution ".$Posting.account"]; ::set AccountName [stringFilter $AccountName]; ::set Class $_account_class_array($AccountName); ::if {![::info exists _account_class_array($AccountName-payroll_class)]} {::continue;} ::set PayrollClass $_account_class_array($AccountName-payroll_class); ::sargs::var::set Distribution ".payroll_class" $PayrollClass; ::if {$Class ne "PAYROLL"} {::continue;} ::set Account [account_get $AccountName]; ::set Employee [[$Account ".employee"] odb_get]; ::if {$Employee eq "" && [::string first "/TOTAL" $PayrollClass]<0} { ::return $SavedArg; } ::if {$CurrentEmployee eq ""} { ::if {$Employee ne ""} { ::set Employee [$Employee odb_master]; ::set CurrentEmployee $Employee; ::incr EmployeeCount; } } else { ::if {$Employee ne ""} { ::set Employee [$Employee odb_master]; ::if {$Employee ne $CurrentEmployee} { ::incr EmployeeCount; } } } } ::lappend NewDistributionItems $Distribution; } ::incr DistributionsCount; ::sargs::var::set JournalItem ".distributions" $NewDistributionItems; ::lappend NewJournalItems $JournalItem; } ::if {$DistributionsCount!=1} {::return $SavedArg;} ::if {$EmployeeCount!=1} {::return $SavedArg;} ::array set GTArrayItem {"IE" 0.0 "IH" 0.0 "PE" 0.0 "HE" 0.0 "FE" 0.0 "PI" 0.0}; ::array set GTArrayTotal [::array get GTArrayItem]; ::foreach DistributionItem $NewDistributionItems { ::if {![::sargs::exists $DistributionItem ".payroll_class"]} {::continue;} ::set PayrollClass [::sargs::get $DistributionItem ".payroll_class"]; ::foreach {Class1 Class2 Class3} {{} {} {}} {;}; ::foreach {Class1 Class2 Class3} [::split $PayrollClass "/"] {;}; ::if {$Class1 ne "PAYROLL"} {::continue;} ::if {[::lsearch -exact {"IE" "IH" "PE" "HE" "FE" "PI"} $Class2]<0} {::continue;} ::set Amount 0; ::foreach Posting {debit credit} { ::if {![::sargs::exists $DistributionItem .$Posting.amount]} {::continue;} ::set Amount [::sargs::get $DistributionItem .$Posting.amount] ::if {$Posting eq "credit"} {::set Amount [::expr $Amount*-1];} ::break; } ::if {$Class3 eq "TOTAL"} { ::set GTArrayTotal($Class2) [::expr $GTArrayTotal($Class2)+$Amount]; } else { ::set GTArrayItem($Class2) [::expr $GTArrayItem($Class2)+$Amount]; } } ::set DistributionItems $NewDistributionItems; ::set NewDistributionItems ""; ::foreach DistributionItem $DistributionItems { ::lappend NewDistributionItems $DistributionItem; ::set PayrollClass [::sargs::get $DistributionItem ".payroll_class"]; ::if {$PayrollClass eq ""} {::continue;} ::foreach {Class1 Class2 Class3} {{} {} {}} {;}; ::foreach {Class1 Class2 Class3} [::split $PayrollClass "/"] {;}; ::if {$Class1 ne "PAYROLL"} {::continue;} ::if {[::lsearch -exact {"IE" "IH" "PE" "HE" "FE" "PI"} $Class2]<0} {::continue;} ::if {$GTArrayItem($Class2)!=[::expr $GTArrayTotal($Class2)*-1]} {::continue;} ::switch -- $Class2 { "IE" {::set Name ".ei_insurable_earnings";} "PE" {::set Name ".cpp_pensionable_earnings";} "IH" {::set Name ".ei_insurable_hours";} "HE" {::set Name ".hsf_earnings";} "FE" {::set Name ".futa_earnings";} "PI" {::set Name ".ppip_insurable_earnings";} } ::if {$Class3 eq "TOTAL"} { ::sargs::var::set DistributionItem ".priority" "ignore"; } else { ::sargs::var::set DistributionItem ".gt_name" $Name; ::sargs::var::set DistributionItem ".gt_amount" $GTArrayItem($Class2); } ::set NewDistributionItems [::lreplace $NewDistributionItems end end $DistributionItem]; } ::set Import_Datum [[$CurrentEmployee ".import_datum"] odb_get]; ::set Benefits_Info [::sargs::get $Import_Datum ".benefits"]; ::if {[::llength [::sargs::subs .structure $Benefits_Info]]} { ::set NewDistributionItems [payroll_distribution_preprocess_benefits $NewDistributionItems $Benefits_Info]; } ::set JournalItems $NewJournalItems; ::set NewJournalItems ""; ::foreach JournalItem $JournalItems { ::if {[::sargs::exists $JournalItem ".distributions"]} { ::sargs::var::set JournalItem ".distributions" $NewDistributionItems; } ::lappend NewJournalItems $JournalItem; } ::sargs::var::set Arg .items $NewJournalItems; ::sargs::var::set Arg .isPayrollTransaction 1; ::set pgqDate [pgq_date_fix [::sargs::get $Arg .date]]; ::sargs::var::set Arg .payrun [payrun_get -employee $CurrentEmployee -date $pgqDate]; ::sargs::var::set Arg .employee $CurrentEmployee; ::return $Arg; } method payroll_distribution_preprocess_benefits {SrcItems SrcInfo} { ::foreach Sub [::sargs::subs .structure $SrcInfo] { ::set Benefit [::sargs::get $SrcInfo $Sub]; ::set Benefit [::sargs::unset $Benefit ".amount"]; ::sargs::var::set Benefit ".amount/debit" 0.0; ::sargs::var::set Benefit ".amount/credit" 0.0; ::for {::set i 0;} {$i<[::llength $SrcItems]} {::incr i;} { ::set Item [::lindex $SrcItems $i]; ::foreach Posting {debit credit} { ::if {![::sargs::exists $Item ".$Posting.account"]} {::continue;} ::set Account [::sargs::get $Item ".$Posting.account"]; ::foreach Sign {debit credit} { ::if {$Account ne [::sargs::get $Benefit ".account/$Sign"]} {::continue;} ::if {[::sargs::get $Benefit ".data/$Sign"] ne ""} {::continue;} ::set Amount [::sargs::get $Item ".$Posting.amount"]; ::if {$Amount eq ""} {::set Amount 0.0;} ::if {$Sign eq "credit"} {::set Amount [::expr 0.0-$Amount];} ::sargs::var::set Benefit ".amount/$Sign" $Amount; ::sargs::var::set Benefit ".item/$Sign" $i; ::sargs::var::set Benefit ".data/$Sign" $Item; } } } ::sargs::var::set SrcInfo $Sub $Benefit; } ::foreach Sub [::sargs::subs .structure $SrcInfo] { ::set Benefit [::sargs::get $SrcInfo $Sub]; ::set SrcInfo [::sargs::unset $SrcInfo $Sub];# Remove the sub (for now) ::if {[::sargs::get $Benefit ".item/debit"] eq ""} {::continue;} ::if {[::sargs::get $Benefit ".item/credit"] eq ""} {::continue;} ::if {[::sargs::get $Benefit ".amount/debit"]!=[::sargs::get $Benefit ".amount/credit"]} {::continue;} ::foreach Sign {debit credit} { ::set Index [::sargs::get $Benefit ".item/$Sign"] ::set SrcItems [::lreplace $SrcItems $Index $Index ""]; } ::sargs::var::set SrcInfo $Sub $Benefit;# Found a 'pair', so put the sub back in. } ::if {![::llength [::sargs::subs .structure $SrcInfo]]} {::return $SrcItems;} ::set NewItems ""; ::for {::set i 0} {$i<[::llength $SrcItems]} {::incr i;} { ::set Item [::lindex $SrcItems $i]; ::if {$Item ne ""} {::lappend NewItems $Item;} } ::set SrcItems $NewItems; ::foreach Sub [::sargs::subs .structure $SrcInfo] { ::set Benefit [::sargs::get $SrcInfo $Sub]; ::foreach Sign {debit credit} { ::set Item [::sargs::get $Benefit ".data/$Sign"]; ::sargs::var::set Item ".benefit" [::sargs::get $Benefit ".benefit"] ::lappend SrcItems $Item; } } ::return $SrcItems; } method payrun_get {args} { ::array set Args $args; ::set Employee $Args(-employee); ::set Payroll [[[$Employee ".payroll"] odb_get] odb_master]; ::set Date $Args(-date); ::set PayrunKey "$Payroll-$Date"; ::if {[::info exists _payruns_array($PayrunKey)]} {::return $_payruns_array($PayrunKey);} ::set PayrunsIndex [[$Payroll ".payruns"] ".index/interactive"]; ::set Payrun ""; ::for {::set PayrunRef [$PayrunsIndex odb_first];} {$PayrunRef ne ""} {::set PayrunRef [$PayrunsIndex odb_next $PayrunRef];} { ::if {[[[$PayrunRef odb_master] ".check_date"] odb_get] eq $Date} {::return [$PayrunRef odb_master];} } ::if {$Payrun eq ""} { ::set Payrun [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/PAYRUN/${_payrollCountry}.odb_deriveds"] odb_factory]; [$Payrun ".folder"] odb_set "file"; [$Payrun ".payroll"] odb_set [$Payroll ".payruns"]; [$Payrun ".check_date"] odb_set $Date; [$Payrun ".status"] qw_set "processed"; ::set PayrunClientdata [$Payrun ".clientdata"]; ::set Clientdata [$PayrunClientdata qw_get]; ::sargs::var::set Clientdata ".import.source" "NV1"; $PayrunClientdata qw_set $Clientdata; commit $Payrun; ::set _payruns_array($PayrunKey) $Payrun; } ::return $Payrun; } method journalentry_count {Arg} { ::set Arg [journalentry_preprocess $Arg]; ::if {![date_is_within_limits $Arg]} { ::return $this; } ::if {[::sargs::exists $Arg ".notes"]} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { increment records-target [text_count [::sargs::get $Arg ".records"]]; } ::if {![::sargs::exists $Arg ".items"]} {::return;} ::foreach Item [::sargs::get $Arg ".items"] { ::set pgqDate [pgq_date_fix [::sargs::get $Arg ".date"]]; transaction_count [::sargs::var::set Item ".date" $pgqDate]; } increment journalEntries-target; } ::if {$::QW::NEWVIEWS::IMPORTER::journal_experiment} { method journalentry_process {Arg} { ::set Arg [journalentry_preprocess $Arg]; ::if {![date_is_within_limits $Arg]} {::return $this;} ::set BalanceAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "JOURNAL_BAL"]; ::if {$BalanceAccount eq ""} { ::set BalanceAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL.odb_deriveds"] odb_factory -odb_id "/JOURNAL_BAL"]; [$BalanceAccount ".folder"] odb_set "file"; [$BalanceAccount ".normal_balance"] odb_set "debit"; [$BalanceAccount ".name"] odb_set "JOURNAL_BAL"; [$BalanceAccount ".description"] odb_set "Journal Balancing Transactions"; [$BalanceAccount ".setup_column"] odb_set 1; $BalanceAccount odb_commit;; } else { ::set BalanceAccount [$BalanceAccount odb_master]; } ::set _in_journalentry 1; ::if {[::sargs::get $Arg .journal] eq ""} {import_error "Encountered a journal entry with no .journal specified.";} ::set Status "Journal entry"; ::if {[::sargs::get $Arg ".isPayrollTransaction"] eq 1} { ::set Journal [$_manager "/OBJECT/NEWVIEWS/JOURNAL/PAYROLL/PAYCHECK/$_payrollCountry$_slashIdPrefix"]; ::set JournalName [[$Journal ".name"] odb_get]; } else { ::set JournalName [::sargs::get $Arg .journal]; ::set Journal [journal_get $JournalName]; } ::set SimpleCount [::sargs::get $Arg .simplecount]; ::set ComplexCount [::sargs::get $Arg .complexcount]; ::set TotalCount [::expr $SimpleCount+$ComplexCount]; ::if {$SimpleCount==1&&$ComplexCount==1} { ::set SimpleItem ""; ::set ComplexItem ""; ::foreach Item [::sargs::get $Arg ".items"] { ::if {[::sargs::exists $Item ".distributions"]} { ::if {$ComplexItem ne ""} {::qw::bug "20031111163049" "Expected only one distribution in journal entry.";} ::set ComplexItem $Item; } else { ::if {$SimpleItem ne ""} {::qw::bug "20031111163315" "Expected only one simple item in journal entry.";} ::set SimpleItem $Item; } } ::if {$ComplexItem eq ""} {::qw::bug "20031111163241" "Could not find expected distribution in journal entry.";} ::if {$SimpleItem eq ""} {::qw::bug "20031111163249" "Could not find expected simple entry in journal entry.";} ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/PAYROLL/PAYCHECK/${_payrollCountry}.odb_deriveds"] odb_factory]; [$Transaction ".employee"] odb_set [[::sargs::get $Arg ".employee"] ".paychecks"]; [$Transaction ".payrun"] odb_set [[::sargs::get $Arg ".payrun"] ".paychecks"]; [$Transaction ".payroll"] odb_set [[[[[::sargs::get $Arg ".employee"] ".payroll"] odb_get] odb_master] ".paychecks"]; } else { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/GENERAL.odb_deriveds"] odb_factory]; } [$Transaction ".folder"] odb_set "file"; [$Transaction ".journal"] odb_set [$Journal ".transactions"]; ::append Status " $JournalName"; ::set Date [pgq_date_fix [::sargs::get $Arg ".date"]]; ::if {$Date ne ""} { [$Transaction ".date"] odb_set $Date; ::append Status " [::qw::date::format $Date {%b %d %Y}]"; } ::set Reference [::string trim [::sargs::get $Arg ".reference"]]; ::if {$Reference ne ""} { [$Transaction ".reference"] odb_set $Reference; ::append Status " $Reference"; } ::set Description [::string trim [::sargs::get $SimpleItem ".description"]]; ::if {$Description ne ""} { [$Transaction ".description"] odb_set $Description; } ::set Notes ""; ::append Notes [::sargs::get $SimpleItem ".notes"]; ::append Notes [::sargs::get $ComplexItem ".notes"]; ::if {$Notes ne ""} { [$Transaction ".notes"] odb_set [text_filter $Notes]; increment notes-processed [text_count $Notes]; } ::set Records ""; ::append Records [::sargs::get $SimpleItem ".records"]; ::append Records [::sargs::get $ComplexItem ".records"]; ::if {$Records ne ""} { [$Transaction ".records"] odb_set [text_filter $Records]; increment records-processed [text_count $Records]; } ::set ItemStatus $Status; ::foreach PostingSign {debit credit} { ::set CrossPostingSign [::expr [::string equal $PostingSign "debit"]?"credit":"debit"]; ::if {![::sargs::exists $SimpleItem ".$PostingSign"]} {::continue;} ::set Posting [::sargs::get $SimpleItem ".$PostingSign"]; ::if {[::sargs::exists $Posting ".account"]} { ::set Name [::sargs::get $Posting ".account"]; ::append ItemStatus " $PostingSign $Name"; ::set Account [account_get $Name]; [$Transaction ".posting/$PostingSign.account"] odb_set [$Account ".postings"]; [$Transaction ".posting/$PostingSign.reconcile"] odb_set [::string trim [::sargs::get $Posting ".reconcile"]] increment ledgerItems-processed; } ::if {[::sargs::exists $Posting ".notes"]} { ::set Notes [::sargs::get $Posting ".notes"]; ::set NewNotes [::sargs::get $Item ".notes"]; ::append Notes [text_filter $NewNotes]; [$Transaction ".notes"] odb_set [text_filter $Notes]; increment notes-processed [text_count $Notes]; } ::if {[::sargs::exists $Posting ".records"]} { ::set Records [[$Transaction ".records"] qw_get]; ::set NewRecords [::sargs::get $Posting ".records"]; ::append Records [text_filter $NewRecords]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count $NewRecords]; } ::break; } status $ItemStatus commit $Transaction; ::foreach Distribution [::sargs::get $ComplexItem ".distributions"] { ::sargs::var::set Distribution ".status" $Status; ::sargs::var::set Distribution ".postingSign" $CrossPostingSign; journal_distribution_process $Transaction $Distribution $Arg; } ::if {[::sargs::exists $Arg ".errors"]} { errors_set $Transaction [::sargs::get $Arg ".errors"]; } ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { } commit $Transaction; increment journalEntries-processed; ::set _in_journalentry 0; batch_check; ::return $this; } ::if {$SimpleCount==2&&$ComplexCount==0} { ::set Items [::sargs::get $Arg ".items"]; ::set Item1 [::lindex $Items 0]; ::set Item2 [::lindex $Items 1]; ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/PAYROLL/PAYCHECK/${_payrollCountry}.odb_deriveds"] odb_factory]; [$Transaction ".employee"] odb_set [[::sargs::get $Arg ".employee"] ".paychecks"]; [$Transaction ".payrun"] odb_set [[::sargs::get $Arg ".payrun"] ".paychecks"]; [$Transaction ".payroll"] odb_set [[[[[::sargs::get $Arg ".employee"] ".payroll"] odb_get] odb_master] ".paychecks"]; } else { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/GENERAL.odb_deriveds"] odb_factory]; } [$Transaction ".folder"] odb_set "file"; [$Transaction ".journal"] odb_set [$Journal ".transactions"]; ::append Status " $JournalName"; ::set Date [pgq_date_fix [::sargs::get $Arg ".date"]]; ::if {$Date ne ""} { [$Transaction ".date"] odb_set $Date; ::append Status " [::qw::date::format $Date {%b %d %Y}]"; } ::set Reference [::string trim [::sargs::get $Arg ".reference"]]; ::if {$Reference ne ""} { [$Transaction ".reference"] odb_set $Reference; ::append Status " $Reference"; } ::set Description1 [::sargs::get $Item1 ".description"] ::set Description2 [::sargs::get $Item2 ".description"] ::set Description $Description1; ::if {$Description1 ne $Description2} { ::append Description " $Description2"; } ::if {$Description ne ""} { [$Transaction ".description"] odb_set $Description; } ::set Notes ""; ::append Notes [::sargs::get $Item1 ".notes"]; ::append Notes [::sargs::get $Item2 ".notes"]; ::append Notes [::sargs::get $Item1 ".debit.notes"]; ::append Notes [::sargs::get $Item1 ".credit.notes"]; ::append Notes [::sargs::get $Item2 ".debit.notes"]; ::append Notes [::sargs::get $Item2 ".credit.notes"]; ::if {$Notes ne ""} { [$Transaction ".notes"] odb_set [text_filter $Notes]; increment notes-processed [text_count $Notes]; } ::set Records ""; ::append Records [::sargs::get $Item1 ".records"]; ::append Records [::sargs::get $Item2 ".records"]; ::append Records [::sargs::get $Item1 ".debit.records"]; ::append Records [::sargs::get $Item1 ".credit.records"]; ::append Records [::sargs::get $Item2 ".debit.records"]; ::append Records [::sargs::get $Item2 ".credit.records"]; ::if {$Records ne ""} { [$Transaction ".records"] odb_set [text_filter $Records]; increment records-processed [text_count $Records]; } ::set ItemStatus $Status; ::set DebitItem ""; ::set CreditItem ""; ::if {[::sargs::exists $Item1 ".debit"]} { ::set DebitItem $Item1; ::set Item1 ""; } else { ::if {[::sargs::exists $Item2 ".debit"]} { ::set DebitItem $Item2; ::set Item2 ""; } } ::if {[::sargs::exists $Item1 ".credit"]} { ::set CreditItem $Item1; ::set Item1 ""; } else { ::if {[::sargs::exists $Item2 ".credit"]} { ::set CreditItem $Item2; ::set Item2 ""; } } ::if {$DebitItem ne ""&&$CreditItem ne ""} { ::set Posting [::sargs::get $DebitItem ".debit"]; ::set Name [::sargs::get $Posting ".account"]; ::append ItemStatus " debit $Name"; ::set Account [account_get $Name]; [$Transaction ".posting/debit.account"] odb_set [$Account ".postings"]; [$Transaction ".posting/debit.reconcile"] odb_set [::string trim [::sargs::get $Posting ".reconcile"]] increment ledgerItems-processed; ::set Posting [::sargs::get $CreditItem ".credit"]; ::set Name [::sargs::get $Posting ".account"]; ::append ItemStatus " credit $Name"; ::set Account [account_get $Name]; [$Transaction ".posting/credit.account"] odb_set [$Account ".postings"]; [$Transaction ".posting/credit.reconcile"] odb_set [::string trim [::sargs::get $Posting ".reconcile"]] increment ledgerItems-processed; [$Transaction ".posting/debit.amount"] odb_set [::sargs::get $DebitItem ".debit.amount"] } status $ItemStatus commit $Transaction; ::if {[::sargs::exists $Arg ".errors"]} { errors_set $Transaction [::sargs::get $Arg ".errors"]; } ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { } commit $Transaction; increment journalEntries-processed; ::set _in_journalentry 0; batch_check; ::return $this; } ::foreach Item [::sargs::get $Arg ".items"] { ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/PAYROLL/PAYCHECK/${_payrollCountry}.odb_deriveds"] odb_factory]; [$Transaction ".employee"] odb_set [[::sargs::get $Arg ".employee"] ".paychecks"]; [$Transaction ".payrun"] odb_set [[::sargs::get $Arg ".payrun"] ".paychecks"]; [$Transaction ".payroll"] odb_set [[[[[::sargs::get $Arg ".employee"] ".payroll"] odb_get] odb_master] ".paychecks"]; } else { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/GENERAL.odb_deriveds"] odb_factory]; } [$Transaction ".folder"] odb_set "file"; [$Transaction ".journal"] odb_set [$Journal ".transactions"]; ::set Status "Journal entry $JournalName"; ::set Date [pgq_date_fix [::sargs::get $Arg ".date"]]; ::if {$Date ne ""} { [$Transaction ".date"] odb_set $Date; ::append Status " [::qw::date::format $Date {%b %d %Y}]"; } ::set Reference [::string trim [::sargs::get $Arg ".reference"]]; ::if {$Reference ne ""} { [$Transaction ".reference"] odb_set $Reference; ::append Status " $Reference"; } ::set Description [::string trim [::sargs::get $Item ".description"]]; ::if {$Description ne ""} { [$Transaction ".description"] odb_set $Description; } ::if {[::sargs::exists $Item ".notes"]} { ::set Notes [[$Transaction ".notes"] qw_get]; ::set NewNotes [::sargs::get $Item ".notes"]; ::append Notes [text_filter $NewNotes]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count $NewNotes]; } ::if {[::sargs::exists $Item ".records"]} { ::set Records [[$Transaction ".records"] qw_get]; ::set NewRecords [::sargs::get $Item ".records"]; ::append Records [text_filter $NewRecords]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count $NewRecords]; } ::set ItemStatus $Status; ::foreach PostingSign {debit credit} { ::if {![::sargs::exists $Item ".$PostingSign"]} {::continue;} ::set CrossPostingSign [::expr [::string equal $PostingSign "debit"]?"credit":"debit"]; ::set Posting [::sargs::get $Item .$PostingSign]; ::if {[::sargs::exists $Posting ".account"]} { ::set Name [::sargs::get $Posting ".account"]; ::append ItemStatus " $PostingSign $Name"; ::set Account [account_get $Name]; [$Transaction ".posting/$PostingSign.account"] odb_set [$Account ".postings"]; [$Transaction ".posting/$CrossPostingSign.account"] odb_set [$BalanceAccount ".postings"]; increment ledgerItems-processed; } ::if {[::sargs::exists $Posting ".notes"]} { ::set Notes [[$Transaction ".notes"] qw_get]; ::set NewNotes [::sargs::get $Posting ".notes"]; ::append Notes [text_filter $NewNotes]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count $NewNotes]; } ::if {[::sargs::exists $Posting ".records"]} { ::set Records [[$Transaction ".records"] qw_get]; ::set NewRecords [::sargs::get $Posting ".records"]; ::append Records [text_filter $NewRecords]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count $NewRecords]; } ::if {[::sargs::exists $Posting ".amount"]} { ::set Amount [::sargs::get $Posting ".amount"]; ::if {$PostingSign eq "debit"} { [$Transaction ".posting/debit.amount"] odb_set $Amount; [$Transaction ".posting/credit.amount"] odb_set [::qw::number::negative $Amount]; [$Transaction ".posting/debit.reconcile"] odb_set [::string trim [::sargs::get $Posting ".reconcile"]]; } else { [$Transaction ".posting/credit.amount"] odb_set $Amount; [$Transaction ".posting/debit.amount"] odb_set [::qw::number::negative $Amount]; [$Transaction ".posting/credit.reconcile"] odb_set [::string trim [::sargs::get $Posting ".reconcile"]]; } ::append ItemStatus " [::format %.2f $Amount]"; } status $ItemStatus ::if {[::sargs::exists $Posting ".distributions"]} { ::qw::bug "20031111145056" "Unexpected distributions encountered." } } ::if {[::sargs::exists $Item ".distributions"]} { commit $Transaction; ::foreach Distribution [::sargs::get $Item ".distributions"] { ::set _status $Status; ::sargs::var::set Distribution ".status" $Status; ::sargs::var::set Distribution ".balanceAccount" $BalanceAccount; journal_distribution_process $Transaction $Distribution $Arg; } } ::if {[::sargs::exists $Arg ".errors"]} { errors_set $Transaction [::sargs::get $Arg ".errors"]; } ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { } commit $Transaction; } increment journalEntries-processed; set _in_journalentry 0; batch_check; } method is_number_and_description {Src} { ::set Src [::string trim $Src]; ::if {$Src eq ""} {::return 0;} ::if {![::regexp {(^-?[1-9]+[0-9]*\.?[0-9]*\ +.*)|(^-?0?\.[0-9]+\ +.*)} $Src]} {::return 0;} ::set _quantity [::lindex $Src 0]; ::set _description [::lindex $Src 1]; ::if {![::string is double $_quantity]} {::return 0;} ::if {$_quantity==0.0} {::return 1;} ::if {$_quantity>0.0 && $_quantity>99999999999.98} {::return 0;} ::if {$_quantity<0.0 && $_quantity<-99999999999.98} {::return 0;} ::return 1; } method journal_distribution_process {LedgerItem Arg SArgs} { ::set Status [::sargs::get $Arg ".status"]; increment distributions-processed; ::if {[::sargs::get $Arg ".priority"] eq "ignore"} { increment ledgerItems-processed; ::return $this; } ::if {[::sargs::exists $Arg ".gt_amount"]} { ::set GTAmount [::sargs::get $Arg ".gt_amount"]; ::set GTName [::sargs::get $Arg ".gt_name"]; ::set Amount [[$LedgerItem $GTName] qw_get]; ::set Amount [::expr $Amount+$GTAmount]; [$LedgerItem $GTName] odb_set $Amount; increment ledgerItems-processed; ::return $this; } ::if {[::sargs::exists $Arg ".benefit"]} { ::set Benefit [::sargs::get $Arg ".benefit"]; ::foreach Posting "debit credit" { ::if {![::sargs::exists $Arg ".$Posting"]} {::continue;} ::if {[::sargs::exists $Arg ".$Posting.amount"]} { ::set Amount [::sargs::get $Arg ".$Posting.amount"]; ::if {$Amount>0.0} { [$LedgerItem ".non_cash_taxable_benefits/$Benefit.amount"] odb_set $Amount; } } } increment ledgerItems-processed; ::return $this; } ::set Transaction [[$LedgerItem ".odb_deriveds"] odb_factory]; [$Transaction ".folder"] odb_set "file"; ::if {[::sargs::exists $Arg ".notes"]} { ::qw::assert {0} ::set Notes [[$Transaction ".notes"] qw_get]; ::append Notes [text_filter [::sargs::get $Arg ".notes"]]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { ::qw::assert {0} ::set Records [[$Transaction ".records"] qw_get]; ::append Records [text_filter [::sargs::get $Arg ".records"]]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count [::sargs::get $Arg ".records"]]; } ::set Description ""; ::if {[::sargs::exists $Arg ".description"]} { ::set Description [::sargs::get $Arg ".description"]; } ::foreach PostingSign "debit credit" { ::if {![::sargs::exists $Arg ".$PostingSign"]} {::continue;} ::set Posting [::sargs::get $Arg .$PostingSign]; ::set CrossPostingSign [::expr [::string equal $PostingSign "debit"]?"credit":"debit"]; ::if {[::sargs::exists $Posting ".account"]} { ::set Name [::sargs::get $Posting ".account"]; ::append Status " $PostingSign $Name"; ::set Account [account_get $Name]; ;#// original (as at 20070503) ::if {[::string first "~" $Name]==0} { ::if {[::string first "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/PAYROLL" [$LedgerItem odb_path]]==0} { ::set Employee [::sargs::get $SArgs ".employee"]; ::if {$Employee ne ""} { ::set TildaName "[[$Employee .employee_id] odb_get]$Name"; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $TildaName]; ::if {$Reference ne ""} { ::set TildaAccount [$Reference odb_master]; ::set EqualName [::string map "~ =" $TildaName]; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $EqualName]; ::if {$Reference eq ""} { ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Object ".folder"] odb_set "file"; [$Object ".nplclass"] odb_set "PAYROLL"; [$Object ".name"] odb_set $EqualName; [$Object ".description"] odb_set [[$TildaAccount ".description"] odb_get]; [$Object ".normal_balance"] odb_set "credit"; [$Object ".setup_column"] odb_set [[$TildaAccount ".setup_column"] odb_get]; [$Object ".underline"] odb_set [[$TildaAccount ".underline"] odb_get]; [$Object ".report"] odb_set [[$TildaAccount ".report"] odb_get]; [$Object ".employee"] odb_set [[$TildaAccount ".employee"] odb_get]; $Object odb_commit; ::set AW_maybe [[[$Transaction odb_base] ".posting/credit.account"] odb_get]; ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { employee_accounts_cleanup_accrual [[[$TildaAccount ".employee"] odb_get] odb_master] $Object $AW_maybe; } } else { ::set Object [$Reference odb_master]; } ::set Account $Object; } } } } ::if {[::sargs::exists $Arg ".postingSign"]} { [$Transaction ".posting/[::sargs::get $Arg .postingSign].account"] odb_set [$Account ".postings"]; } else { [$Transaction ".posting/$PostingSign.account"] odb_set [$Account ".postings"]; } ::if {[::sargs::get $Arg ".balanceAccount"] ne ""} { [$Transaction ".posting/$CrossPostingSign.account"] odb_set [[::sargs::get $Arg ".balanceAccount"] ".postings"]; } increment ledgerItems-processed; ::if {[::sargs::exists $Posting ".reconcile"]} { [$Transaction ".posting/$PostingSign.reconcile"] odb_set [::string trim [::sargs::get $Posting ".reconcile"]]; } } ::if {[::sargs::exists $Posting ".amount"]} { ::set Amount [::sargs::get $Posting ".amount"]; ::append Status " [::format %.2f $Amount]"; ::if {[::sargs::exists $Arg ".postingSign"]} { ::if {[::sargs::get $Arg .postingSign] ne $PostingSign} { ::qw::number::var::negative Amount; } } ::if {$PostingSign eq "debit"} { ::if {[is_number_and_description $Description]} { ::if {$Amount<0.0} {::qw::number::var::negative _quantity;} [$Transaction ".posting/debit.quantity"] odb_set $_quantity; ::if {$_quantity!=0.0} { [$Transaction ".posting/debit.rate"] odb_set [::qw::number::divide $Amount $_quantity]; } } [$Transaction ".posting/debit.amount"] odb_set $Amount; [$Transaction ".posting/credit.amount"] odb_set [::qw::number::negative $Amount]; } else { ::if {[is_number_and_description $Description]} { ::if {$Amount<0.0} {::qw::number::var::negative _quantity;} [$Transaction ".posting/credit.quantity"] odb_set $_quantity; ::if {$_quantity!=0.0} { [$Transaction ".posting/credit.rate"] odb_set [::qw::number::divide $Amount $_quantity]; } } [$Transaction ".posting/debit.amount"] odb_set [::qw::number::negative $Amount]; [$Transaction ".posting/credit.amount"] odb_set $Amount; } } ::if {[::sargs::exists $Posting ".notes"]} { ::set Notes [[$Transaction ".notes"] qw_get]; ::set NewNotes [::sargs::get $Posting ".notes"]; ::append Notes [text_filter $NewNotes]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count $NewNotes]; } ::if {[::sargs::exists $Posting ".records"]} { ::set Records [[$Transaction ".records"] qw_get]; ::set NewRecords [::sargs::get $Posting ".records"]; ::append Records [text_filter $NewRecords]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count $NewRecords]; } } ::if {[::sargs::exists $Arg ".description"]} { [$Transaction ".description"] odb_set [::sargs::get $Arg ".description"]; } status $Status; ;#// too much noise on the status line for distributions commit $Transaction; } } else { } method payroll_transaction_preprocess {Arg} { ::set SavedArg $Arg; ::set IsPayrollTransaction 0; ::sargs::var::set SavedArg .isPayrollTransaction $IsPayrollTransaction; ::if {$_import_action eq "count"} {::return $SavedArg;} ::if {!$_payroll_is_installed} {::return $SavedArg;} ::if {![::sargs::exists $Arg ".distributions"]} {::return $SavedArg;} ::set EmployeeCount 0; ::set CurrentEmployee ""; ::set NewDistributionItems ""; ::foreach Distribution [::sargs::get $Arg ".distributions"] { ::foreach Posting {debit credit} { ::if {![::sargs::exists $Distribution ".$Posting.account"]} {::continue;} ::set AccountName [::sargs::get $Distribution ".$Posting.account"]; ::set AccountName [stringFilter $AccountName]; ::set Class $_account_class_array($AccountName); ::if {![::info exists _account_class_array($AccountName-payroll_class)]} {::continue;} ::set PayrollClass $_account_class_array($AccountName-payroll_class); ::sargs::var::set Distribution ".payroll_class" $PayrollClass; ::if {$Class ne "PAYROLL"} {::continue;} ::set Account [account_get $AccountName]; ::set Employee [[$Account ".employee"] odb_get]; ::if {$Employee eq "" && [::string first "/TOTAL" $PayrollClass]<0} { ::return $SavedArg; } ::if {$CurrentEmployee eq ""} { ::if {$Employee ne ""} { ::set Employee [$Employee odb_master]; ::set CurrentEmployee $Employee; ::sargs::var::set Arg ".employee" $Employee; ::incr EmployeeCount; } } else { ::if {$Employee ne ""} { ::set Employee [$Employee odb_master]; ::if {$Employee ne $CurrentEmployee} { ::incr EmployeeCount; } } } } ::lappend NewDistributionItems $Distribution; } ::sargs::var::set Arg ".distributions" $NewDistributionItems; ::if {$EmployeeCount!=1} {::return $SavedArg;} ::array set GTArrayItem {"IE" 0.0 "IH" 0.0 "PE" 0.0 "HE" 0.0 "FE" 0.0 "PI" 0.0}; ::array set GTArrayTotal [::array get GTArrayItem]; ::foreach DistributionItem $NewDistributionItems { ::if {![::sargs::exists $DistributionItem ".payroll_class"]} {::continue;} ::set PayrollClass [::sargs::get $DistributionItem ".payroll_class"]; ::foreach {Class1 Class2 Class3} {{} {} {}} {;}; ::foreach {Class1 Class2 Class3} [::split $PayrollClass "/"] {;}; ::if {$Class1 ne "PAYROLL"} {::continue;} ::if {[::lsearch -exact {"IE" "IH" "PE" "HE" "FE" "PI"} $Class2]<0} {::continue;} ::set Amount 0; ::foreach Posting {debit credit} { ::if {![::sargs::exists $DistributionItem .$Posting.amount]} {::continue;} ::set Amount [::sargs::get $DistributionItem .$Posting.amount] ::if {$Posting eq "credit"} {::set Amount [::expr $Amount*-1];} ::break; } ::if {$Class3 eq "TOTAL"} { ::set GTArrayTotal($Class2) [::expr $GTArrayTotal($Class2)+$Amount]; } else { ::set GTArrayItem($Class2) [::expr $GTArrayItem($Class2)+$Amount]; } } ::set DistributionItems $NewDistributionItems; ::set NewDistributionItems ""; ::foreach DistributionItem $DistributionItems { ::lappend NewDistributionItems $DistributionItem; ::set PayrollClass [::sargs::get $DistributionItem ".payroll_class"]; ::if {$PayrollClass eq ""} {::continue;} ::foreach {Class1 Class2 Class3} {{} {} {}} {;}; ::foreach {Class1 Class2 Class3} [::split $PayrollClass "/"] {;}; ::if {$Class1 ne "PAYROLL"} {::continue;} ::if {[::lsearch -exact {"IE" "IH" "PE" "HE" "FE" "PI"} $Class2]<0} {::continue;} ::if {$GTArrayItem($Class2)!=[::expr $GTArrayTotal($Class2)*-1]} {::continue;} ::switch -- $Class2 { "IE" {::set Name ".ei_insurable_earnings";} "PE" {::set Name ".cpp_pensionable_earnings";} "IH" {::set Name ".ei_insurable_hours";} "HE" {::set Name ".hsf_earnings";} "FE" {::set Name ".futa_earnings";} "PI" {::set Name ".ppip_insurable_earnings";} } ::if {$Class3 eq "TOTAL"} { ::sargs::var::set DistributionItem ".priority" "ignore"; } else { ::sargs::var::set DistributionItem ".gt_name" $Name; ::sargs::var::set DistributionItem ".gt_amount" $GTArrayItem($Class2); } ::set NewDistributionItems [::lreplace $NewDistributionItems end end $DistributionItem]; } ::set Import_Datum [[$CurrentEmployee ".import_datum"] odb_get]; ::set Benefits_Info [::sargs::get $Import_Datum ".benefits"]; ::if {[::llength [::sargs::subs .structure $Benefits_Info]]} { ::set NewDistributionItems [payroll_distribution_preprocess_benefits $NewDistributionItems $Benefits_Info]; } ::sargs::var::set Arg ".distributions" $NewDistributionItems; ::sargs::var::set Arg .isPayrollTransaction 1; ::set pgqDate [pgq_date_fix [::sargs::get $Arg .date]]; ::sargs::var::set Arg .payrun [payrun_get -employee $CurrentEmployee -date $pgqDate]; ::sargs::var::set Arg .employee $CurrentEmployee; ::return $Arg; } method transaction_process {Arg} { ::set Arg [payroll_transaction_preprocess $Arg]; ::if {![date_is_within_limits $Arg]} {::return $this;} ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/PAYROLL/PAYCHECK/${_payrollCountry}.odb_deriveds"] odb_factory]; [$Transaction ".journal"] odb_set [$_manager "/OBJECT/NEWVIEWS/JOURNAL/PAYROLL/PAYCHECK/$_payrollCountry$_slashIdPrefix.transactions"]; [$Transaction ".employee"] odb_set [[::sargs::get $Arg ".employee"] ".paychecks"]; [$Transaction ".payrun"] odb_set [[::sargs::get $Arg ".payrun"] ".paychecks"]; [$Transaction ".payroll"] odb_set [[[[[::sargs::get $Arg ".employee"] ".payroll"] odb_get] odb_master] ".paychecks"]; } else { ::set Transaction [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/GENERAL.odb_deriveds"] odb_factory]; [$Transaction ".journal"] odb_set [$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT/DOSDEFAULT.transactions"]; } [$Transaction ".folder"] odb_set "file"; ::set Status "LedgerItem"; [$Transaction ".date"] odb_set [pgq_date_fix [::sargs::get $Arg ".date"]]; ::append Status ",[::qw::date::format [::sargs::get $Arg .date] {%b %d %Y}]"; ::if {[::sargs::get $Arg ".reference"] ne ""} { [$Transaction ".reference"] odb_set [::string trim [::sargs::get $Arg ".reference"]]; ::append Status ",[::string trim [::sargs::get $Arg .reference]]"; } ::if {[::sargs::exists $Arg ".notes"]} { ::set Notes [[$Transaction ".notes"] qw_get]; ::append Notes [text_filter [::sargs::get $Arg ".notes"]]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { ::set Records [[$Transaction ".records"] qw_get]; ::append Records [text_filter [::sargs::get $Arg ".records"]]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count [::sargs::get $Arg ".records"]]; } ::set ItemStatus $Status; ::set Amount ""; ::foreach Posting "debit credit" { ::if {![::sargs::exists $Arg ".$Posting"]} {continue;} ::if {[::sargs::exists $Arg ".$Posting.account"]} { ::set Name [::sargs::get $Arg ".$Posting.account"]; ::append ItemStatus ",$Posting $Name"; ::set Account [account_get $Name]; [$Transaction ".posting/$Posting.account"] odb_set [$Account ".postings"]; increment ledgerItems-processed; } ::if {[::sargs::exists $Arg ".$Posting.amount"]} { ::set Amount [::sargs::get $Arg ".$Posting.amount"]; ::append ItemStatus " [::expr abs($Amount)]"; ::if {$Posting eq "debit"} { [$Transaction ".posting/debit.amount"] odb_set $Amount; [$Transaction ".posting/credit.amount"] odb_set [::qw::number::negative $Amount]; } else { [$Transaction ".posting/debit.amount"] odb_set [::qw::number::negative $Amount]; [$Transaction ".posting/credit.amount"] odb_set $Amount; } } ::if {[::sargs::exists $Arg ".$Posting.notes"]} { ::set Notes [[$Transaction ".notes"] qw_get]; ::append Notes [text_filter [::sargs::get $Arg ".$Posting.notes"]]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count [::sargs::get $Arg ".$Posting.notes"]]; } ::if {[::sargs::exists $Arg ".$Posting.records"]} { ::set Records [[$Transaction ".records"] qw_get]; ::append Records [text_filter [::sargs::get $Arg ".$Posting.records"]]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count [::sargs::get $Arg ".$Posting.records"]]; } } ::if {[::sargs::get $Arg ".description"] ne ""} { [$Transaction ".description"] odb_set [::sargs::get $Arg ".description"] ::append Status ",[::sargs::get $Arg .description]"; } ::if {[::sargs::exists $Arg ".distributions"]} { commit $Transaction; ::foreach Distribution [::sargs::get $Arg ".distributions"] { ::set _status $Status; distribution_process $Transaction $Distribution $Arg; } } else { status $ItemStatus; } ::foreach Posting {debit credit} { ::if {[::sargs::get $Arg ".$Posting.reconcile"] ne ""} { [$Transaction ".posting/$Posting.reconcile"] odb_set [::string trim [::sargs::get $Arg ".$Posting.reconcile"]]; } } ::if {[::sargs::get $Arg .isPayrollTransaction] eq 1} { } commit $Transaction; batch_check; } method qw_real_add {Arg1 Arg2} { ::return [::format %.2f [::qw::number::round2 [::expr {$Arg1+$Arg2}]]]; } method pgq_date_fix {Date} { ::if {$Date eq ""} {::return 19030101;} ::set Year [::string range $Date 0 3]; ::if {$Year<1903} {::return 19030101;} ::if {$Year>2037} {::return 20371231;} ::return $Date; } method date_is_within_limits {Arg} { ::set Date [pgq_date_fix [::sargs::get $Arg ".date"]]; ::if {[::qw::date::difference $Date $_yearly_res_begin_date "day"]<0} { ::return 0; } ::if {$_import_action eq "count"} {::return 1;} ::if {[::qw::date::difference $Date $_full_res_begin_date "day"]>=0} { ::return 1; } ::if {[::qw::date::difference $Date $_daily_res_begin_date "day"]>=0} { } else { ::if {[::qw::date::difference $Date $_monthly_res_begin_date "day"]>=0} { ::set Date [::qw::date::set $Date "day" [::qw::date::get $Date "days_in_month"]]; } else { ::if {[::qw::date::difference $Date $_yearly_res_begin_date "day"]>=0} { ::if {$_current_fiscal_year_end eq ""} { ::set Fields [[[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/ODDS_AND_ENDS"] ".fields"] odb_get]; ::set _current_fiscal_year_end [::sargs::get $Fields ".current_fiscal_year_end"]; } ::if {$_current_fiscal_year_end eq ""} { import_error "No fiscal year end found in exported books, yearly compression cannot be performed."; } ::if {[::qw::date::get $Date year]<1903} { ::set Date 19030101; } else { ::set FYE $_current_fiscal_year_end; ::while {[::qw::date::difference $FYE $Date "month"]>=12} { ::set FYE [::qw::date::add $FYE "year" "-1"]; } ::set Date $FYE; } } else { import_error "Compression date calculation error."; } } } ::sargs::var::set Arg ".compression_date" [::string range $Date 0 7]; ::set JournalEntry [::sargs::exists $Arg ".journal"]; ::if {$JournalEntry} { journalentry_compress $Arg } else { transaction_compress $Arg; } batch_check; ::return 0; } method format_date {Src} { ::return [::qw::date::format $Src {%d %b %Y}]; } method journalentry_compress {Arg} { compressionDataStore $Arg; ::set Date [pgq_date_fix [::sargs::get $Arg .date]]; ::set Status "Compressing journal entry [::sargs::get $Arg .journal] [::qw::date::format [::sargs::get $Arg .date] {%b %d %Y}]"; ::set Date [pgq_date_fix [::sargs::get $Arg ".compression_date"]]; ::if {[::sargs::get $Arg ".reference"] ne ""} {::append Status " ,[::string trim [::sargs::get $Arg .reference]]";} ::if {[::sargs::exists $Arg ".notes"]} {increment notes-processed [text_count [::sargs::get $Arg ".notes"]];} ::if {[::sargs::exists $Arg ".records"]} {increment records-processed [text_count [::sargs::get $Arg ".records"]];} ::set Items [::sargs::get $Arg ".items"]; ::if {$Items eq ""} { status $Status; increment journalEntries-processed; ::return; } ::set SimpleCount [::sargs::get $Arg .simplecount]; ::if {!$SimpleCount} { ::puts "Error: Encountered a journal entry with no simple items"; } ::foreach Item $Items { ::set ItemStatus $Status; ::array unset ItemArgs; ::array set ItemArgs $Item; ::if {[::info exists ItemArgs(.notes)]} {increment notes-processed [text_count $ItemArgs(.notes)];} ::if {[::info exists ItemArgs(.records)]} {increment records-processed [text_count $ItemArgs(.records)];} ::foreach {Posting CrossPosting} {debit credit credit debit} { ::if {![::info exists ItemArgs(.$Posting)]} {::continue;} ::array unset PostingArgs; ::array set PostingArgs $ItemArgs(.$Posting); ::if {[::info exists PostingArgs(.account)]} { ::set Name $PostingArgs(.account); increment ledgerItems-processed; ::if {[::info exists PostingArgs(.amount)]} { ::set Amount $PostingArgs(.amount); ::if {$Amount!=0.0} { ::set UsePosting $Posting; ::if {$UsePosting eq "debit"&&$Amount<0.0} {::set UsePosting $CrossPosting;} ::if {$UsePosting eq "credit"&&$Amount>0.0} {::set UsePosting $CrossPosting;} ::append ItemStatus " $UsePosting $Name [::expr abs($Amount)]"; status $ItemStatus; ::set Reconcile ""; ::if {[::info exists PostingArgs(.reconcile)]} { ::set Reconcile $PostingArgs(.reconcile); } posting_compress -date $Date -name $Name -posting $UsePosting -amount $Amount -reconcile $Reconcile; } } } ::if {[::info exists PostingArgs(.notes)]} {increment notes-processed [text_count $PostingArgs(.notes)];} ::if {[::info exists PostingArgs(.records)]} {increment records-processed [text_count $PostingArgs(.records)];} } ::if {[::info exists ItemArgs(.distributions)]} { ::foreach Distribution $ItemArgs(.distributions) { ::set ItemStatus $Status; increment distributions-processed; ::if {[::sargs::exists $Distribution ".gt_amount"]} { increment ledgerItems-processed; ::continue; } ::if {[::sargs::get $Distribution ".priority"] eq "ignore"} { increment ledgerItems-processed; ::continue; } ::if {[::sargs::exists $Distribution ".benefit"]} { increment ledgerItems-processed; ::continue; } ::foreach {Posting CrossPosting} {debit credit credit debit} { ::if {![::sargs::exists $Distribution ".$Posting"]} {::continue;} ::if {[::sargs::exists $Distribution ".$Posting.account"]} { ::set Name [::sargs::get $Distribution ".$Posting.account"]; ::if {[::sargs::exists $Distribution ".$Posting.amount"]} { ::set Amount [::sargs::get $Distribution ".$Posting.amount"]; ::if {$Amount!=0.0} { ::set UsePosting $Posting; ::if {$UsePosting eq "debit"&&$Amount<0.0} {::set UsePosting $CrossPosting;} ::if {$UsePosting eq "credit"&&$Amount>0.0} {::set UsePosting $CrossPosting;} ::append ItemStatus " $UsePosting $Name [::expr abs($Amount)]"; status $ItemStatus; ::set Reconcile ""; ::if {[::sargs::exists $Distribution ".$Posting.reconcile"]} { ::set Reconcile [::sargs::get $Distribution ".$Posting.reconcile"]; } posting_compress -date $Date -name $Name -posting $UsePosting -amount $Amount -reconcile $Reconcile; } } increment ledgerItems-processed; } ::if {[::sargs::exists $Distribution ".$Posting.notes"]} {increment notes-processed [text_count [::sargs::get $Distribution ".$Posting.notes"]];} ::if {[::sargs::exists $Distribution ".$Posting.records"]} {increment records-processed [text_count [::sargs::get $Distribution ".$Posting.records"]];} } } } } increment journalEntries-processed; } method posting_compress {args} { ::array set Args $args; ::if {![::info exists _compressionHeaders($Args(-date))]} { ::set _compressionHeaders($Args(-date)) 0; increment compressionHeaders-target; } ::incr _compressionHeaders($Args(-date)); ::set CompressionAmount 0.0; ::set Key $Args(-date)-$Args(-name)-$Args(-posting); ::if {$Args(-reconcile) eq ""} { ::set State "open" } else { ::set State "closed" } ::if {[::info exists _compressionItems($Key)]} { ::set CompressionAmount $_compressionItems($Key); } else { increment compressionItems-target 1; } ::set CompressionAmount [qw_real_add $CompressionAmount $Args(-amount)]; ::set _compressionItems($Key) $CompressionAmount; ::return $this; } method transaction_compress {Arg} { compressionDataStore $Arg; ::set Date [pgq_date_fix [::sargs::get $Arg ".date"]]; ::set Status "Compressing,[::qw::date::format $Date {%b %d %Y}]"; ::set Date [pgq_date_fix [::sargs::get $Arg ".compression_date"]]; ::if {[::sargs::get $Arg ".reference"] ne ""} {::append Status ",[::string trim [::sargs::get $Arg .reference]]";} ::if {[::sargs::exists $Arg ".notes"]} {increment notes-processed [text_count [::sargs::get $Arg ".notes"]];} ::if {[::sargs::exists $Arg ".records"]} {increment records-processed [text_count [::sargs::get $Arg ".records"]];} ::set ItemStatus $Status; ::set HeaderName ""; ::foreach {Posting CrossPosting} "debit credit credit debit" { ::if {![::sargs::exists $Arg ".$Posting"]} {::continue;} ::if {[::sargs::exists $Arg ".$Posting.notes"]} {increment notes-processed [text_count [::sargs::get $Arg ".$Posting.notes"]];} ::if {[::sargs::exists $Arg ".$Posting.records"]} {increment records-processed [text_count [::sargs::get $Arg ".$Posting.records"]];} ::if {![::sargs::exists $Arg ".$Posting.account"]} {::continue;} ::set HeaderName [::sargs::get $Arg ".$Posting.account"]; ::append ItemStatus ",$Posting $HeaderName"; increment ledgerItems-processed; ::if {[::sargs::exists $Arg ".$CrossPosting.account"]} { ::if {$HeaderName eq [::sargs::get $Arg ".$CrossPosting.account"]} {::continue;} } ::if {[::sargs::exists $Arg ".$Posting.amount"]} { ::set Amount [::sargs::get $Arg ".$Posting.amount"]; ::if {$Amount!=0.0} { ::append ItemStatus " [::expr abs($Amount)]"; ::set Reconcile ""; ::if {[::sargs::exists $Arg ".$Posting.reconcile"]} { ::set Reconcile [::sargs::get $Arg ".$Posting.reconcile"]; } posting_compress -date $Date -name $HeaderName -posting $Posting -amount $Amount -reconcile $Reconcile; } } } ::if {[::sargs::get $Arg ".description"] ne ""} {::append Status ",[::sargs::get $Arg .description]";} ::if {[::sargs::exists $Arg ".distributions"]} { ::set CompressionTotal [distribution_compress $Arg]; ::if {$CompressionTotal!=0.0} { ::if {$CompressionTotal>0.0} { ::set Posting "credit"; } else { ::set Posting "debit"; } ::set Reconcile ""; ::if {[::sargs::exists $Arg ".$Posting.reconcile"]} { ::set Reconcile [::sargs::get $Arg ".$Posting.reconcile"]; } posting_compress -date $Date -name $HeaderName -posting $Posting -amount [::expr {$CompressionTotal*-1.0}] -reconcile $Reconcile; } } else { status $ItemStatus; } ::return 0; } method distribution_compress {Arg} { ::set CompressionTotal 0.0; ::set Date [pgq_date_fix [::sargs::get $Arg ".compression_date"]]; ::foreach Distribution [::sargs::get $Arg ".distributions"] { ::set Status $_status; increment distributions-processed; ::if {[::sargs::exists $Distribution ".gt_amount"]} { increment ledgerItems-processed; ::continue; } ::if {[::sargs::get $Distribution ".priority"] eq "ignore"} { increment ledgerItems-processed; ::continue; } ::if {[::sargs::exists $Distribution ".benefit"]} { increment ledgerItems-processed; ::continue; } ::foreach {Posting CrossPosting} {debit credit credit debit} { ::if {![::sargs::exists $Distribution ".$Posting"]} {::continue;} ::if {[::sargs::exists $Distribution ".$Posting.notes"]} {increment notes-processed [text_count [::sargs::get $Distribution ".$Posting.notes"]];} ::if {[::sargs::exists $Distribution ".$Posting.records"]} {increment records-processed [text_count [::sargs::get $Distribution ".$Posting.records"]];} ::if {![::sargs::exists $Distribution ".$Posting.account"]} {::continue;} increment ledgerItems-processed; ::set Name [::sargs::get $Distribution ".$Posting.account"]; ::if {[::sargs::exists $Distribution ".$Posting.amount"]} { ::set Amount [::sargs::get $Distribution ".$Posting.amount"]; ::if {$Amount!=0.0} { ::set UsePosting $Posting; ::if {$UsePosting eq "debit"&&$Amount<0.0} {::set UsePosting $CrossPosting;} ::if {$UsePosting eq "credit"&&$Amount>0.0} {::set UsePosting $CrossPosting;} ::set Reconcile ""; ::if {[::sargs::exists $Distribution ".$Posting.reconcile"]} { ::set Reconcile [::sargs::get $Distribution ".$Posting.reconcile"]; } posting_compress -date $Date -name $Name -posting $UsePosting -amount $Amount -reconcile $Reconcile; ::set CompressionTotal [::expr $CompressionTotal+$Amount]; } } } status $Status; } ::return $CompressionTotal; } method compressionDataStore {Src} { ::sargs::var::set Src ".slashIdPrefix" $_slashIdPrefix; ::set Date [pgq_date_fix [::sargs::get $Src ".date"]]; ::if {[::sargs::get $Src ".isPayrollTransaction"] eq 1} { ::sargs::var::set Src ".payroll_country" $_payrollCountry; } ::set CompressionDate [pgq_date_fix [::sargs::get $Src ".compression_date"]]; ::sargs::var::unset Src ".compression_date"; ::set Src [compressionStructureNormalize $Src]; ::set Src [compressionDataIdsSet $Src]; ::if {![::info exists _compression_import_datums($CompressionDate)]} { ::set Transaction [compressionTransactionGet $CompressionDate]; ::set _compression_import_datums($CompressionDate) [[$Transaction ".import_datum"] qw_get]; } ::set Items [::sargs::get $_compression_import_datums($CompressionDate) ".compressed_transactions"]; ::lappend Items $Src; ::sargs::var::set _compression_import_datums($CompressionDate) ".compressed_transactions" $Items; } method compressionStructureNormalize {Src} { ::if {[::sargs::exists $Src ".journal"]} { ::set Items [::sargs::get $Src ".items"]; ::sargs::var::unset Src ".items"; ::set ICount 1; ::foreach Item $Items { ::set Item [compressionStructureNormalizeDistributions $Item]; ::sargs::var::set Src ".items/$ICount" $Item; ::incr ICount; } ::return $Src; } ::return [compressionStructureNormalizeDistributions $Src]; } method compressionStructureNormalizeDistributions {Src} { ::set Distributions [::sargs::get $Src ".distributions"]; ::if {$Distributions eq ""} {::return $Src;} ::sargs::var::unset Src ".distributions"; ::set DCount 1; ::foreach Distribution $Distributions { ::sargs::var::set Src ".distributions/$DCount" $Distribution; ::incr DCount; } ::return $Src; } method compressionDataIdsSet {Src} { ::set Result ""; ::set PathList [::sargs::select_field .structure $Src .field .account]; ::foreach Path $PathList { ::set AccountName [::sargs::get $Src $Path.account]; ::set Account [account_get $AccountName]; ::sargs::var::set Src $Path.account_id $Account; } ::set PathList [::sargs::select_field .structure $Src .field ".journal"]; ::foreach Path $PathList { ::set JournalName [::sargs::get $Src $Path.journal]; ::if {[::sargs::get $Src ".isPayrollTransaction"] eq 1} { ::set Journal [$_manager "/OBJECT/NEWVIEWS/JOURNAL/PAYROLL/PAYCHECK/$_payrollCountry$_slashIdPrefix"]; } else { ::set Journal [journal_get $JournalName]; } ::sargs::var::set Src $Path.journal_id $Journal; } ::return $Src; } method compressionJournalGet {} { ::set Journal [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT.odb_deriveds.index/name"] odb_find_key ".name" "COMPRESSED_TRANSACTIONS"]; ::if {$Journal ne ""} { ::return [$Journal odb_master]; } ::set Journal [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT.odb_deriveds"] odb_factory -odb_id "/COMPRESSED_TRANSACTIONS"]; [$Journal ".name"] odb_set "COMPRESSED_TRANSACTIONS"; [$Journal ".description"] odb_set "Compressed Transactions"; [$Journal ".tags"] odb_set "financial"; commit $Journal; ::return $Journal; } method compressionAccountGet {} { ::set HeaderAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "COMPRESSED_TRANSACTIONS"]; ::if {$HeaderAccount ne ""} { ::return [$HeaderAccount odb_master]; } ::set HeaderAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL.odb_deriveds"] odb_factory -odb_id "/COMPRESSED_TRANSACTIONS"]; [$HeaderAccount ".folder"] odb_set "file"; [$HeaderAccount ".normal_balance"] odb_set "credit"; [$HeaderAccount ".name"] odb_set "COMPRESSED_TRANSACTIONS"; [$HeaderAccount ".description"] odb_set "Compressed Transactions"; commit $HeaderAccount; ::return $HeaderAccount; } method compressionTransactionGet {Date} { ::set Journal [compressionJournalGet]; ::set Header [[$Journal ".transactions.index/date"] odb_find_key .tag financial .date $Date]; ::if {$Header ne ""} { ::return [$Header odb_master]; } ::set Header [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/GENERAL.odb_deriveds"] odb_factory]; [$Header ".folder"] odb_set "file"; [$Header ".journal"] odb_set [$Journal ".transactions"]; [$Header ".date"] odb_set $Date; [$Header ".description"] odb_set "Detail Compression Transaction"; [$Header ".posting/credit.account"] odb_set [[compressionAccountGet] ".postings"]; commit $Header; ::return $Header } method compressionHeadersPost {} { ::if {$_compression_headers_done} { ::return $this; } ::if {!$_pre_compression_post_shutdown_done} { ::set _pre_compression_post_shutdown_done 1; ::if {![::array size _compressionHeaders]} {::return $this;} batch_complete; } ::set Headers [::array names _compressionHeaders]; ::if {![::llength $Headers]} {::return $this;} ::set Journal [compressionJournalGet]; ::set Headers [::lsort $Headers]; ::foreach Date $Headers { status "Posting Compression Transaction,[::qw::date::format $Date {%b %d %Y}]"; ::set Header [compressionTransactionGet $Date]; ::set Items [::array names _compressionItems $Date*]; ::set Items [::lsort $Items]; ::foreach Name $Items { ::set Item [[$Header ".odb_deriveds"] odb_factory]; [$Item ".folder"] odb_set "file"; ::set Account [::string map "$Date- {}" $Name]; ::set Account [::string map "-debit {}" $Account]; ::set Account [::string map "-credit {}" $Account]; [$Item ".posting/debit.account"] odb_set [[account_get $Account] ".postings"]; [$Item ".posting/debit.amount"] odb_set $_compressionItems($Name); [$Item ".posting/credit.amount"] odb_set [::qw::number::negative $_compressionItems($Name)]; [$Item ".description"] odb_set "Detail Compression Transaction"; [$Item ".posting/debit.reconcile"] odb_set "R"; commit $Item; increment compressionItems-processed; ::unset _compressionItems($Name); batch_check_compressionItems; } increment compressionHeaders-processed; ::unset _compressionHeaders($Date); } ::set _compression_headers_done 1; } method transaction_count {Arg} { ::if {![date_is_within_limits $Arg]} {::return $this;} ::if {[::sargs::exists $Arg ".notes"]} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { increment records-target [text_count [::sargs::get $Arg ".records"]]; } ::foreach Name {.debit .credit} { ::if {[::sargs::exists $Arg $Name]} { increment ledgerItems-target; ::if {[::sargs::exists $Arg "$Name.notes"]} { increment notes-target [text_count [::sargs::get $Arg "$Name.notes"]]; } ::if {[::sargs::exists $Arg "$Name.records"]} { increment records-target [text_count [::sargs::get $Arg "$Name.records"]]; } } } ::foreach Distribution [::sargs::get $Arg ".distributions"] { distribution_count $Distribution; } } method distribution_process {LedgerItem Arg SArgs} { ::set Status $_status; increment distributions-processed; ::if {[::sargs::get $Arg ".priority"] eq "ignore"} { increment ledgerItems-processed; ::return $this; } ::if {[::sargs::exists $Arg ".gt_amount"]} { ::set GTAmount [::sargs::get $Arg ".gt_amount"]; ::set GTName [::sargs::get $Arg ".gt_name"]; ::set Amount [[$LedgerItem $GTName] qw_get]; ::set Amount [::expr $Amount+$GTAmount]; [$LedgerItem $GTName] odb_set $Amount; increment ledgerItems-processed; ::return $this; } ::if {[::sargs::exists $Arg ".benefit"]} { ::set Benefit [::sargs::get $Arg ".benefit"]; ::foreach Posting "debit credit" { ::if {![::sargs::exists $Arg ".$Posting"]} {::continue;} ::if {[::sargs::exists $Arg ".$Posting.amount"]} { ::set Amount [::sargs::get $Arg ".$Posting.amount"]; ::if {$Amount>0.0} { [$LedgerItem ".non_cash_taxable_benefits/$Benefit.amount"] odb_set $Amount; } } } increment ledgerItems-processed; ::return $this; } ::set Transaction [[$LedgerItem ".odb_deriveds"] odb_factory]; [$Transaction ".folder"] odb_set "file"; ::if {[::sargs::exists $Arg ".notes"]} { ::qw::assert {0} ::set Notes [[$Transaction ".notes"] qw_get]; ::append Notes [text_filter [::sargs::get $Arg ".notes"]]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { ::qw::assert {0} ::set Records [[$Transaction ".records"] qw_get]; ::append Records [text_filter [::sargs::get $Arg ".records"]]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count [::sargs::get $Arg ".records"]]; } ::set Description ""; ::if {[::sargs::exists $Arg ".description"]} { ::set Description [::sargs::get $Arg ".description"]; } ::foreach Posting "debit credit" { ::if {![::sargs::exists $Arg ".$Posting"]} {continue;} ::if {[::sargs::exists $Arg ".$Posting.account"]} { ::set Name [::sargs::get $Arg ".$Posting.account"]; ::append Status ",$Posting $Name"; ::set Account [account_get $Name]; ::if {[::string first "~" $Name]==0} { ::if {[::string first "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION/PAYROLL" [$LedgerItem odb_path]]==0} { ::set Employee [::sargs::get $SArgs ".employee"]; ::if {$Employee ne ""} { ::set TildaName "[[$Employee .employee_id] odb_get]$Name"; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $TildaName]; ::if {$Reference ne ""} { ::set TildaAccount [$Reference odb_master]; ::set EqualName [::string map "~ =" $TildaName]; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $EqualName]; ::if {$Reference eq ""} { ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Object ".folder"] odb_set "file"; [$Object ".nplclass"] odb_set "PAYROLL"; [$Object ".name"] odb_set $EqualName; [$Object ".description"] odb_set [[$TildaAccount ".description"] odb_get]; [$Object ".normal_balance"] odb_set "credit"; [$Object ".setup_column"] odb_set [[$TildaAccount ".setup_column"] odb_get]; [$Object ".underline"] odb_set [[$TildaAccount ".underline"] odb_get]; [$Object ".report"] odb_set [[$TildaAccount ".report"] odb_get]; [$Object ".employee"] odb_set [[$TildaAccount ".employee"] odb_get]; $Object odb_commit; ::set AW_maybe [[[$Transaction odb_base] ".posting/credit.account"] odb_get]; ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { employee_accounts_cleanup_accrual [[[$TildaAccount ".employee"] odb_get] odb_master] $Object $AW_maybe; } } else { ::set Object [$Reference odb_master]; } ::set Account $Object; } } } } [$Transaction ".posting/$Posting.account"] odb_set [$Account ".postings"]; increment ledgerItems-processed; ::if {[::sargs::exists $Arg ".$Posting.reconcile"]} { [$Transaction ".posting/$Posting.reconcile"] odb_set [::string trim [::sargs::get $Arg ".$Posting.reconcile"]]; } } ::if {[::sargs::exists $Arg ".$Posting.amount"]} { ::set Amount [::sargs::get $Arg ".$Posting.amount"]; ::append Status " [::expr abs($Amount)]"; ::if {$Posting eq "debit"} { ::if {[is_number_and_description $Description]} { ::if {$Amount<0.0} {::qw::number::var::negative _quantity;} [$Transaction ".posting/debit.quantity"] odb_set $_quantity; ::if {$_quantity!=0.0} { [$Transaction ".posting/debit.rate"] odb_set [::qw::number::divide $Amount $_quantity]; } } [$Transaction ".posting/debit.amount"] odb_set $Amount; [$Transaction ".posting/credit.amount"] odb_set [::qw::number::negative $Amount]; } else { ::if {[is_number_and_description $Description]} { ::if {$Amount<0.0} {::qw::number::var::negative _quantity;} [$Transaction ".posting/credit.quantity"] odb_set $_quantity; ::if {$_quantity!=0.0} { [$Transaction ".posting/credit.rate"] odb_set [::qw::number::divide $Amount $_quantity]; } } [$Transaction ".posting/debit.amount"] odb_set [::qw::number::negative $Amount]; [$Transaction ".posting/credit.amount"] odb_set $Amount; } } ::if {[::sargs::exists $Arg ".$Posting.notes"]} { ::set Notes [[$Transaction ".notes"] qw_get]; ::append Notes [text_filter [::sargs::get $Arg ".$Posting.notes"]]; [$Transaction ".notes"] odb_set $Notes; increment notes-processed [text_count [::sargs::get $Arg ".$Posting.notes"]]; } ::if {[::sargs::exists $Arg ".$Posting.records"]} { ::set Records [[$Transaction ".records"] qw_get]; ::append Records [text_filter [::sargs::get $Arg ".$Posting.records"]]; [$Transaction ".records"] odb_set $Records; increment records-processed [text_count [::sargs::get $Arg ".$Posting.records"]]; } } ::if {[::sargs::exists $Arg ".description"]} { [$Transaction ".description"] odb_set [::sargs::get $Arg ".description"]; } commit $Transaction; status $Status; } method distribution_count {Arg} { increment distributions-target; ::if {[::sargs::exists $Arg ".notes"]} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { increment records-target [text_count [::sargs::get $Arg ".records"]]; } ::foreach Name {.debit .credit} { ::if {[::sargs::exists $Arg "$Name.account"]} { increment ledgerItems-target; ::if {[::sargs::exists $Arg "$Name.notes"]} { increment notes-target [text_count [::sargs::get $Arg "$Name.notes"]]; } ::if {[::sargs::exists $Arg "$Name.records"]} { increment records-target [text_count [::sargs::get $Arg "$Name.records"]]; } } } } method procedures_process {Arg} { ::set Master [$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE"]; ::if {[::sargs::exists $Arg ".notes"]} { [$Master ".notes"] odb_set [text_filter [::sargs::get $Arg ".notes"]]; increment notes-processed [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { [$Master ".records"] odb_set [text_filter [::sargs::get $Arg ".records"]]; increment records-processed [text_count [::sargs::get $Arg ".records"]]; } commit $Master; return $this; } method procedure_process {Arg} { ::set Name [::sargs::get $Arg ".name"]; ::set Master [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set $Name; [$Master ".folder"] odb_set "file"; ::set Status "Procedure,$Name"; ::if {[::sargs::exists $Arg ".description"]} { [$Master ".description"] odb_set [::sargs::get $Arg ".description"]; ::append Status ",[::sargs::get $Arg ".description"]"; } ::if {[::sargs::exists $Arg ".notes"]} { [$Master ".notes"] odb_set [text_filter [::sargs::get $Arg ".notes"]]; increment notes-processed [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { [$Master ".records"] odb_set [text_filter [::sargs::get $Arg ".records"]]; increment records-processed [text_count [::sargs::get $Arg ".records"]]; } ::if {[::sargs::exists $Arg ".source"]} { [$Master ".source"] odb_set [text_filter [::sargs::get $Arg ".source"]]; increment notes-processed [text_count [::sargs::get $Arg ".source"]]; } commit $Master; status $Status; increment procedures-processed; ::if {$_table(procedures-processed)==$_table(procedures-target)} { buildArrays; loadNplSetup; } batch_check; } method procedures_count {Arg} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; } method procedure_count {Arg} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; increment notes-target [text_count [::sargs::get $Arg ".source"]]; increment procedures-target; ::set Name [::sargs::get $Arg ".name"]; ::if {$Name eq $_export_procedure_name} { ::set ProcedureInfo [procedure_info [::sargs::get $Arg ".source"]]; ::set Version [::sargs::get $ProcedureInfo ".version"]; ::if {$Version<0} {import_error "NV1 data was exported with an unknown version of NVEXPORT, version $_export_version_minimum or greater is required.";} ::if {$Version<$_export_version_minimum} {import_error "NV1 data was exported with version $Version of NVEXPORT, version $_export_version_minimum or greater is required.";} } } method procedure_info {Src} { ::set Library ""; ::set Version -1 ::sargs::var::set Result ".library" $Library ".version" $Version; ::if {$Src eq ""} { ::return $Result; } ::set String [::lindex $Src 0]; ::set Pos [::string first "@external(library=" $String];# #// ) (so parenthesis match in the script) ::if {$Pos<0} { ::return $Result; } ::incr Pos 18; ::set String [::string range $String $Pos end]; ::set String [::split $String ","]; ::set Library [::lindex $String 0]; ::set Version [::lindex [::split [::lindex $String 1] "="] 1]; ::if {$Version eq ""||![::string is integer $Version]} { ::return $Result; } ::return [::sargs::var::set Result ".library" $Library ".version" $Version]; } method printers_process {Arg} { ::set Master [$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PRINTER"]; ::if {[::sargs::exists $Arg ".notes"]} { [$Master ".notes"] odb_set [text_filter [::sargs::get $Arg ".notes"]]; increment notes-processed [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { [$Master ".records"] odb_set [text_filter [::sargs::get $Arg ".records"]]; increment records-processed [text_count [::sargs::get $Arg ".records"]]; } commit $Master; } method printer_process {Arg} { ::set Name [::sargs::get $Arg ".name"]; ::set Master [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PRINTER$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set $Name; [$Master ".folder"] odb_set "file"; ::set Status "Printer,$Name"; ::if {[::sargs::exists $Arg ".description"]} { [$Master ".description"] odb_set [::sargs::get $Arg ".description"]; ::append Status ",[::sargs::get $Arg ".description"]"; } ::if {[::sargs::exists $Arg ".notes"]} { [$Master ".notes"] odb_set [text_filter [::sargs::get $Arg ".notes"]]; increment notes-processed [text_count [::sargs::get $Arg ".notes"]]; } ::if {[::sargs::exists $Arg ".records"]} { [$Master ".records"] odb_set [text_filter [::sargs::get $Arg ".records"]]; increment records-processed [text_count [::sargs::get $Arg ".records"]]; } ::if {[::sargs::exists $Arg ".sequences"]} { [$Master ".sequences"] odb_set [text_filter [::sargs::get $Arg ".sequences"]]; } commit $Master; status $Status; increment printers-processed; } method printers_count {Arg} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; } method printer_count {Arg} { increment notes-target [text_count [::sargs::get $Arg ".notes"]]; increment records-target [text_count [::sargs::get $Arg ".records"]]; increment printers-target; } public method abort_check {} { ::if {!$_abort_requested} {::return;} ::if {$_batch_type eq "TCL"} { control_message_send "*ABORT_REQUEST*"; ::set _abort_requested 0; ::return $this; } ::set Result [::qw::dialog::confirm [::qw::list { .title "Stop the import?" .text "Confirm that you want to stop the import.\n\nStop the import now?\nOr press Resume to resume the import." /button { /ok { .text "Stop" } /cancel { .text "Resume" } } }]]; ::raise $itk_component(hull); ::if {$Result} { ::set _is_aborted 1; ::if {!$_is_batch} { import_error ".text {The import was aborted by the user.} .priority abort"; } } ::set _abort_requested 0; } public method abort_requested {} { ::set _abort_requested 1; } public method abort {} { ::set _is_aborted 1; ::return; } public method pause_begin {} { ::if {[::subst $$_suspended_state_variable_id]} {::return;} ::set $_suspended_state_variable_id 1; ::set _suspended_status [status]; status "Import paused"; ::tkwait variable $_suspended_state_variable_id; } public method pause_end {} { ::if {![::subst $$_suspended_state_variable_id]} {::return;} status $_suspended_status; ::set $_suspended_state_variable_id 0; } method batch_check {} { ::if {!$_is_batch} {::return;} ::if {$_in_journalentry} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(ledgerItems-processed)-$_batch_ledger_items_at_load<$_batch_ledger_items_per_batch} {::return;} batch_complete; } method batch_check_notesconvert {} { ::if {!$_is_batch} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(notesconvert-processed)-$_batch_notesconvert_items_at_load<$_batch_account_items_per_batch} {::return;} batch_complete; } method batch_check_totaltos {} { ::if {!$_is_batch} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(totaltos-processed)-$_batch_totalto_items_at_load<$_batch_totalto_items_per_batch} {::return;} batch_complete; } method batch_check_employees {} { ::if {!$_is_batch} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(employees-processed)-$_batch_employee_items_at_load<$_batch_employee_items_per_batch} {::return;} batch_complete; } method batch_check_accounts {} { ::if {!$_is_batch} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(all_accounts-processed)-$_batch_account_items_at_load<$_batch_account_items_per_batch} {::return;} batch_complete; } method batch_check_compressionItems {} { ::if {!$_is_batch} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(compressionItems-processed)-$_batch_compression_items_at_load<$_batch_compression_items_per_batch} {::return;} batch_complete; } method batch_check_history {} { ::if {!$_is_batch} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(history-processed)-$_batch_history_items_at_load<$_batch_history_items_per_batch} {::return;} batch_complete; } method batch_check_budget {} { ::if {!$_is_batch} {::return;} ::if {$_is_aborted} {batch_complete;} ::if {$_table(budgets-processed)-$_batch_budget_items_at_load<$_batch_budget_items_per_batch} {::return;} batch_complete; } method batch_complete {} { ::qw::throw [::sargs \ .text "The end of a batch was reached." \ .id "batch_complete" \ .help_id 271820050404144040 \ ]; } protected method import {} { ::if {!$_is_batch&&[[$_manager cpp_database] cpp_access] ne "singleuser"} { ::set Result [::qw::dialog::confirm [::qw::list { .title "Proceed with import?" \ .text "Database $_database_path is open with multiuser access.\nLarge batch-oriented operations are faster with singleuser access.\n\nProceed with the import now?\nOr cancel and import the data later." /button { /ok { .text "Proceed" } /cancel { .text "Cancel" } } }]]; ::if {!$Result} { ::qw::itcl_delete_object $this; return; } } ::set _save_audit_state [$_manager cpp_audit_state_get]; ::incr ::qw::control(progress_window_disable_count); ::set _save_is_avoiding_date_range_errors $::qw::control(is_avoiding_date_range_errors); $_manager cpp_audit_state_set "disabled"; ::set ::qw::control(is_avoiding_date_range_errors) 1; configure -title "[::string tolower [::file normalize $_database_path]] - Importing DOS NewViews Data."; $itk_interior.controls.action configure -text Abort -command [::itcl::code $this abort_requested]; ::qw::try { ::set _is_importing 1; ::set _stopwatch [::QW::STOPWATCH #auto]; ::if {$_batch_number==1} { ::set _import_action "count"; status "Counting and checking import objects ..."; source $_exported_path; status "Import objects counted and checked OK"; } ::if {[$_manager cpp_find "/OBJECT/NEWVIEWS"] eq ""} { status "Installing NewViews general accounting classes."; ::qw::script::source \ .script.path [::file join $::qw_library object newviews install.qw_script] \ .database $_manager \ .command application \ ; ::if {$::qw::control(airtech)} { ::qw::odb::source object/newviews/airtech/install.qw_tcl; } } ::if {[$_manager cpp_find "/OBJECT/NEWVIEWS/JOURNAL/GENERAL/DOSIMPORT"] eq ""} { ::set JournalImport [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL.odb_deriveds"] odb_factory -odb_id "/DOSIMPORT"]; [$JournalImport ".name"] odb_set "DOSIMPORT"; [$JournalImport ".description"] odb_set "DOS NewViews Import"; commit $JournalImport; ::set JournalImport [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL/DOSIMPORT.odb_deriveds"] odb_factory -odb_id "/JOURNAL_ACCOUNTS"]; [$JournalImport ".name"] odb_set "JOURNAL_ACCOUNTS"; [$JournalImport ".description"] odb_set "Journal Accounts"; [$JournalImport ".tags"] odb_set "financial"; commit $JournalImport; ::set JournalImport [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL/DOSIMPORT.odb_deriveds"] odb_factory -odb_id "/DOSDEFAULT"]; [$JournalImport ".name"] odb_set "DOSDEFAULT"; [$JournalImport ".description"] odb_set "DOS Default"; [$JournalImport ".tags"] odb_set "financial"; commit $JournalImport; } ::if {$_idPrefix ne ""} { ::set _slashIdPrefix [::string toupper "/$_idPrefix"]; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE.odb_deriveds.index/name"] odb_find_key ".name" $_idPrefix]; ::if {$Reference eq ""} { ::set Master [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PRINTER.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; commit $Master; } } buildArrays; loadNplSetup; ::if {$_payrollCountry eq ""} {::set _payrollCountry "CANADA";} ::if {[$_manager cpp_find "/OBJECT/NEWVIEWS/PAYROLL"] eq ""} { status "Installing NewViews payroll classes."; ::qw::script::source \ .script.path [::file join $::qw_library object newviews payroll install.qw_script] \ .database $_manager \ .command application \ ; } ::if {[$_manager cpp_find "/OBJECT/NEWVIEWS/PAYROLL/CANADA"] eq ""} { status "Installing NewViews payroll Canada classes."; ::qw::script::source \ .script.path [::file join $::qw_library object newviews payroll canada install.qw_script] \ .database $_manager \ .command application \ ; } ::if {[$_manager cpp_find "/OBJECT/NEWVIEWS/PAYROLL/USA"] eq ""} { status "Installing NewViews payroll USA classes."; ::qw::script::source \ .script.path [::file join $::qw_library object newviews payroll usa install.qw_script] \ .database $_manager \ .command application \ ; } ::if {$_idPrefix ne ""} { ::set _slashIdPrefix [::string toupper "/$_idPrefix"]; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL.odb_deriveds.index/name"] odb_find_key ".name" $_idPrefix]; ::if {$Reference eq ""} { ::foreach Aclass "/AP /AR /BANK /CGS /EXPENSE /GENERAL /INVENTORY /PAYROLL/CANADA /PAYROLL/USA /SALES /TOTAL" { ::set Master [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT$Aclass.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; [$Master ".folder"] odb_set "folder"; commit $Master; } ::set Master [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/NV1_PURGED_HISTORY"]; [$Master ".name"] odb_set "NV1_PURGED_HISTORY"; [$Master ".description"] odb_set "NV1 Purged History Balancing Account"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/BUDGET_BALANCE"]; [$Master ".name"] odb_set "BUDGET_BALANCE"; [$Master ".description"] odb_set "Budget Balance"; [$Master ".normal_balance"] odb_set "debit"; [$Master ".normal_representation"] odb_set "periodic"; [$Master ".folder"] odb_set "file"; [$Master ".clientdata"] odb_set [::sargs::set [[$Master ".clientdata"] odb_get] ".nv2.kludge/convert.totalto" 1]; [$Master ".nplclass"] odb_set "GENERAL"; [$Master ".setup_column"] odb_set 1; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/JOURNAL_BAL"]; [$Master ".name"] odb_set "JOURNAL_BAL"; [$Master ".description"] odb_set "Journal Balancing Transactions"; $Master odb_commit;; ::set Master [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/COMPRESSED_TRANSACTIONS"]; [$Master ".name"] odb_set "COMPRESSED_TRANSACTIONS"; [$Master ".description"] odb_set "Compressed Transactions"; commit $Master; ::foreach Jclass "/BANK/DEPOSIT /BANK/PAYMENT /PAYROLL/TIMECARD /PAYROLL/PAYCHECK/CANADA /PAYROLL/PAYCHECK/USA" { ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL$Jclass.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; [$Master ".tags"] odb_set "financial f_$_idPrefix"; commit $Master; } ::foreach Jclass "/GENERAL /PURCHASE /SALES" { ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL$Jclass.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; commit $Master; } ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/BANK/DEPOSIT$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set "BD"; [$Master ".description"] odb_set "Bank Deposits"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/BANK/PAYMENT$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set "BP"; [$Master ".description"] odb_set "Bank Payments"; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/PURCHASE$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set "PO"; [$Master ".description"] odb_set "Purchase Orders"; [$Master ".tags"] odb_set "order o_$_idPrefix"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/PURCHASE$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set "PI"; [$Master ".description"] odb_set "Purchase Invoices"; [$Master ".tags"] odb_set "financial f_$_idPrefix"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/SALES$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set "SO"; [$Master ".description"] odb_set "Sales Orders"; [$Master ".tags"] odb_set "order o_$_idPrefix"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/SALES$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Master ".name"] odb_set "SI"; [$Master ".description"] odb_set "Sales Invoices"; [$Master ".tags"] odb_set "financial f_$_idPrefix"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/DOSIMPORT"]; [$Master ".name"] odb_set "DOSIMPORT"; [$Master ".description"] odb_set "DOS NewViews Import"; [$Master ".tags"] odb_set "financial f_$_idPrefix"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT.odb_deriveds"] odb_factory -odb_id "/JOURNAL_ACCOUNTS"]; [$Master ".name"] odb_set "JOURNAL_ACCOUNTS"; [$Master ".description"] odb_set "Journal Accounts"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT.odb_deriveds"] odb_factory -odb_id "/DOSDEFAULT"]; [$Master ".name"] odb_set "DOSDEFAULT"; [$Master ".description"] odb_set "DOS Default"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT.odb_deriveds"] odb_factory -odb_id "/NV1_PURGED_HISTORY"]; [$Master ".name"] odb_set "NV1_PURGED_HISTORY"; [$Master ".description"] odb_set "NV1 Purged History"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/DEFAULT"]; [$Master ".name"] odb_set "DEFAULT"; [$Master ".description"] odb_set "Default"; [$Master ".tags"] odb_set "financial f_$_idPrefix"; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix.odb_deriveds"] odb_factory -odb_id "/BUDGET"]; [$Master ".name"] odb_set "BUDGET"; [$Master ".description"] odb_set "Budget"; [$Master ".tags"] odb_set "budget b_$_idPrefix"; commit $Master; ::foreach Pclass "/CANADA /USA" { ::set Master [[$_manager "/OBJECT/NEWVIEWS/PAYROLL$Pclass.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; commit $Master; ::set Master [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/EMPLOYEE$Pclass.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; commit $Master; } ::set Master [[$_manager "/OBJECT/NEWVIEWS/REPORT.odb_deriveds"] odb_factory -odb_id $_slashIdPrefix]; [$Master ".name"] odb_set $_idPrefix; [$Master ".description"] odb_set $_idDescription; commit $Master; } } ::set _import_action "process"; source $_exported_path; compression_import_datums_save; status "Committing /OBJECT/NEWVIEWS..."; $_manager cpp_commit; do_account_postprocessing; ::set NewViewsClientdata [$_manager "/OBJECT/NEWVIEWS.clientdata"]; ::set Clientdata [$NewViewsClientdata qw_get]; ::sargs::var::set Clientdata ".import.date" [::qw::date::from_number clock_seconds [::clock seconds]]; $NewViewsClientdata qw_set $Clientdata; status "Checking for semiloops..." ::qw::script::source \ .script.path [::file join $::qw_library object newviews account total totalto_semiloop_check.qw_script] \ .database $_database \ .find_first_semiloop 1 \ ; status "Committing object database manager ..." $_manager cpp_commit .commit_before_skip 1; ::wm protocol $itk_component(hull) WM_DELETE_WINDOW [::itcl::code $this dismiss]; ::if {$_history_errors} { control_message_send "*USER_MESSAGE* Account history check failed with $_history_errors history errors"; ::foreach Error $_history_error_list {control_message_send "*NON_FATAL_ERROR* $Error";} } ::if {$_is_batch} { batch_shutdown "DONE"; } else { $_manager cpp_audit_state_set $_save_audit_state; ::incr ::qw::control(progress_window_disable_count) -1; ::set ::qw::control(is_avoiding_date_range_errors) $_save_is_avoiding_date_range_errors_state; } $itk_interior.controls.action configure -text "Dismiss" -command [::itcl::code $this dismiss]; ::if {!$_history_errors} { ::set Status "Import completed successfully"; } else { ::set Status "Import completed with $_history_errors history errors"; ::bell; } ::if {$_batch_type ne "TCL"} { ::append Status " in [::expr {[$_stopwatch seconds]+$_seconds}] seconds"; } status "$Status."; ::set _is_importing 0; ::return $this; } catch Exception { ::puts "import.tcl error: $Exception"; ::puts "errorInfo: $::errorInfo" ::if {[::sargs::find_field_value .structure $Exception .field ".id" .value "batch_complete"]} { status "The import has reached the end of a batch." batch_shutdown; ::return $this; } status "Aborting object database manager ..." ::set _is_importing 0; $_manager cpp_audit_state_set $_save_audit_state; ::incr ::qw::control(progress_window_disable_count) -1; ::set ::qw::control(is_avoiding_date_range_errors) $_save_is_avoiding_date_range_errors_state; $itk_interior.controls.action configure -text "Dismiss" -command [::itcl::code $this dismiss]; import_error [::qw::exception::parent $Exception "The import has been stopped."]; ::if {[::sargs::find_field_value .structure $Exception .field ".priority" .value "abort"]} { ::raise $itk_component(hull); status "User aborted the import and rolled back all work in progress." ::return $this; } status "Aborted the import due to an error and rolled back all work in progress." ::qw::dialog::error [::qw::exception \ "Encountered an error while importing newviews data into $_database_path." \ "Aborted the import and rolled back all work in progress." \ $Exception ]; ::raise $itk_component(hull); ::return $this; } } method source {Path} { ::qw::try { ::if {$_exported_handle eq ""} { ::set _exported_handle [::open $Path r]; ::seek $_exported_handle $_exported_seek; } else { ::seek $_exported_handle 0; } ::if {$_account_preprocessing_in_progress} {do_account_preprocessing} ::set Buffer ""; ::while {[::gets $_exported_handle Line]>=0} { ::append Buffer $Line "\n"; ::if {[::info complete $Buffer]} { abort_check; ::if {![::llength $Buffer]} {::continue;} ::if {[::lindex $Buffer 0] eq ""} {::continue;} ::set Line $Buffer; ::set Buffer ""; ::if {[::llength $Line]!=2} {import_error "Encountered invalid syntax: \"$Line\"";} ::set Command [::lindex $Line 0]; ::set Structure [::lindex $Line 1]; ::if {[::sargs::get $Structure ".priority"] eq "ignore"} { ::continue; } ::if {[::info exists _table($Command-doit)]} { ::if {!$_table($Command-doit)} { ::continue; } } ::switch -- [::lindex $Line 0] { "\#" {::continue;} "/*" {::continue;} "home" - "oddsAndEnds" - "report" - "account" - "journal" - "purged_history" - "transaction" - "journalentry" - "procedures" - "procedure" - "printers" - "employee" - "printer" { "${Command}_$_import_action" $Structure; } default { ::puts "default:$Line" ::if {[::info function $Command] eq ""} { ::continue; } } } ::if {$_table(all_accounts-processed) && $_table(all_accounts-processed)==$_table(all_accounts-target)} { do_account_preprocessing; } } ::if {$_import_action eq "count"} {batch_check;} } ::if {$_import_action eq "process"} { ::set _end_of_import_file_reached 1; ::if {!$_is_batch} { ::close $_exported_handle; ::set _exported_handle ""; } } } catch Exception { ::puts $::errorInfo; ::qw::throw $Exception; } } method do_account_preprocessing {} { ::if {$_account_preprocessing_is_done} {::return $this;} ::set _account_preprocessing_in_progress 1; newviews_notes_process; status "Total-tos process start."; totaltos_process; payroll_accounts_process; ::set _account_preprocessing_is_done 1; ::set _account_preprocessing_in_progress 0; } method do_account_postprocessing {} { ::if {$_account_postprocessing_is_done} {::return $this;} ::set _account_postprocessing_in_progress 1; status "Posting compression transactions"; compressionHeadersPost; status "Copying procedure settings"; copyBLKCOPYSettings; copySETUPIsettings; status "Setting budgets"; budgets_process; user_options_set; ::if {[::info exists _table(checkBooksHistory-doit)]} { ::if {$_table(checkBooksHistory-doit)} { check_books_history; } } journal_report_destroy; ::if {$_payroll_is_installed} { employee_accounts_cleanup; total_government_totals_accounts_destroy; } ::set _account_postprocessing_is_done 1; ::set _account_postprocessing_in_progress 0; } method journal_report_destroy {} { ::array set Settings [procedureSettingsParse "NVEXPORT" [procedureRecords "NVEXPORT"]]; ::array set _nvexportArray $Settings(0); ::set JournalReport [::string trim $_nvexportArray(.journalReport)]; ::if {$JournalReport eq ""} {::return;} ::set Report [report_get $JournalReport]; ::set Index [[$Report ".accounts"] ".index/interactive"]; ::set Accounts 0; ::set RefList [$Index odb_masters ".order_is_kept 1"]; ::set Remainder ""; ::set Flag 1; ::while {$RefList ne ""&&$Flag} { ::set Flag 0; ::foreach Ref $RefList { ::set Account [$Ref odb_master]; ::set Name [[$Account ".name"] odb_get]; ::set Description [[$Account ".description"] odb_get]; ::if {[[$Account ".line_type"] odb_get] eq "text_line"} { status "Removed journal report text line with description \"$Description\"."; [$Ref odb_master] odb_destroy; ::continue; } ::if {[[$Account ".total.kids"] odb_items]!=0} { ::lappend Remainder $Ref; ::continue; } ::if {[[$Account ".postings.index/date"] odb_items]!=0} { ::lappend Remainder $Ref; ::continue; } status "Removed empty journal account \"$Name\"."; $Account odb_destroy; ::set Flag 1; } ::set RefList $Remainder; ::set Remainder ""; } ::if {[::llength $RefList]==0} { status "Removed empty journal report \"$JournalReport\"."; $Report odb_destroy; ::return; } status "Could not remove journal report \"$JournalReport\", [::llength $RefList] account items could not be deleted."; } public method user_options_set {} { ::set Master [$_manager "/OBJECT/SYSTEM/USER"]; ::array set OddsAndEndsFields [[[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/ODDS_AND_ENDS"] ".fields"] odb_get]; ::if {[::info exists OddsAndEndsFields(.date_format)]} { ::set DateFormat $OddsAndEndsFields(.date_format); ::if {$DateFormat ne ""&&[::string is integer $DateFormat]&&$DateFormat>=0&&$DateFormat<=16} { ::set DateFormat [::qw::date::nv1_date_format_to_nv2 $DateFormat]; [$Master ".options.date.format"] odb_set $DateFormat; } } [$Master ".options.date.entry"] odb_set "ddmmyyyy"; commit $Master; } protected method centerOnScreen {} { ::update idletasks; ::if {$_geometry_at_shutdown ne ""} { ::wm geometry $itk_component(hull) $_geometry_at_shutdown; ::wm deiconify $itk_component(hull); ::raise $itk_component(hull); ::return $this } ::set Width [::winfo reqwidth $itk_component(hull)] ::set Height [::winfo reqheight $itk_component(hull)] ::wm minsize $itk_component(hull) $Width $Height ::set x [::expr ([::winfo screenwidth $itk_component(hull)]-$Width)/2] ::set y [::expr ([::winfo screenheight $itk_component(hull)]-$Height)/2] ::wm geometry $itk_component(hull) +$x+$y ::wm deiconify $itk_component(hull); ::raise $itk_component(hull); ::return $this; } protected method directory_select {} { ::qw::try { ::set Tail [::lindex [::file split $_database_directory] end]; ::switch -- [::string tolower $Tail] { "workstation" {import_error "Attempted to import NewViews accounting data into a workstation database.";} "server" {import_error "Attempted to import NewViews accounting data into a server database.";} } } catch Exception { $itk_interior.controls.action configure -text "Dismiss" -command [::itcl::code $this dismiss]; status "Attempted to import NewViews accounting data into $_database_directory." import_error "Importing Newviews accounting data into $_database_directory is prohibited." $Exception; } ::set _exported_path [::qw::dialog::file [::qw::list { .title "Select exported NewViews 1 file." .files 1 .default [::file join $_database_directory exported] }]]; ::if {$_exported_path eq ""} {return "";} ::raise $itk_component(hull); configure -title "Ready to import newviews data." status "$_database_path ready to import newviews data ..." $itk_interior.controls.action configure -text "Press to begin import." -command [::itcl::code $this import]; } protected method commit {Object {s_args ""}} { $Object odb_commit $s_args; ::if {$_commit_sequence>=$_commit_limit} { $_manager cpp_commit; ::set _commit_sequence 0; } $_manager cpp_ping; } public method dismiss {} { ::if {$_is_batch} { ::qw::shutdown ::return; } ::qw::itcl_delete_object $this; } protected method payroll_accounts_process {} { employees_count; employees_process; employee_accounts_check; ::return $this; } public method check_payroll_accounts {} { ::if {$_employees_have_been_processed} {::return $this;} ::array set PayrollAccounts {}; ::foreach Name [::array names _account_class_array] { ::if {[::string first "-payroll_class" $Name]>=0} {::continue;} ::if {$_account_class_array($Name) ne "PAYROLL"} {::continue;} ::set PayrollAccounts($Name) 0; } ::foreach Employee $_employee_list { ::foreach Item [::sargs::get $Employee ".accounts"] { ::set Name [::sargs::get $Item ".name"]; ::array unset PayrollAccounts $Name; } ::foreach Item [::sargs::get $Employee ".other_accounts"] { ::set Name [::sargs::get $Item ".name"]; ::array unset PayrollAccounts $Name; } } ::append _payroll_convert_notes "ORPHAN EMPLOYEE ACCOUNT CHECK\n"; ::if {[::llength [::array names PayrollAccounts]]==0} { ::append _payroll_convert_notes "All Employee accounts are attached to an employee.\n\n"; ::return; } ::append _payroll_convert_notes "* The [::llength [::array names PayrollAccounts]] accounts listed below were exported from NV1 with the type \"Employee\",\n"; ::append _payroll_convert_notes "but they could not be attached to an NV2 employee. The accounts have been\n"; ::append _payroll_convert_notes "deleted and re-created as General accounts.\n"; ::foreach Name [::array names PayrollAccounts] { status "Changing account $Name from type EMPLOYEE to type GENERAL"; ::set Address [accountOdbAddressFromName $Name]; change_account_class $Address "GENERAL" "GENERAL"; ::append _payroll_convert_notes " $Name\n"; } ::append _payroll_convert_notes "\n"; } public method dumpTimeStats {} { ::if {![::array size _timeStats]} {::return $this;} ::puts "Time Stats ---------------------------------------------------------------"; ::foreach Name $_timeStats(Names) { ::set AvgTime [::expr double($_timeStats($Name-time))/$_timeStats($Name-count)]; ::puts -nonewline "$Name count: $_timeStats($Name-count)"; ::puts -nonewline " average: $AvgTime microseconds"; ::puts -nonewline " slowest: $_timeStats($Name-slowest)"; ::puts -nonewline " fastest: $_timeStats($Name-fastest)"; ::puts ""; ::for {::set Count 1;} {$Count<=$_timeStats($Name-count)} {::incr Count;} { ::puts "[::format %7i $Count]: $_timeStats($Name-$Count)"; } } ::puts "--------------------------------------------------------------------------"; ::return $this; } public method catalogEmployeeAccounts {} { ::set Structure ""; ::set ECount 0; ::set Count 0; ::foreach Employee $_employee_list { ::incr ECount; ::unset -nocomplain Data; ::array set Data $Employee; ::set SuffixList ""; ::foreach AccountItem $Data(.accounts) { ::unset -nocomplain ItemArray; ::array set ItemArray $AccountItem; ::lappend SuffixList $ItemArray(.suffix); } ::set SortedSuffixList [::lsort $SuffixList]; ::set Found 0; ::foreach Sub [::sargs::subs .structure $Structure] { ::if {[::sargs::get $Structure $Sub.list] eq $SortedSuffixList} {::set Found 1;::break;} } ::if {$Found} { ::sargs::var::set Structure $Sub.count [::expr [::sargs::get $Structure $Sub.count]+1]; } else { ::incr Count; ::sargs::var::set Structure /$Count.list $SortedSuffixList; ::sargs::var::set Structure /$Count.count 1; } } ::return $this; } method procedureSettingsParse {Procedure Records} { ::if {![::info exists _procedureRecordArray($Procedure)]} {import_error "No record array for procedure $Procedure."} ::array set Result {}; ::array set RecordArray $Records; ::set SettingsList [::list [::list "" $_procedureRecordArray($Procedure-base)]]; ::set Names ""; ::for {set i 0} {$i<=24} {::incr i} { ::set RecordNumber [largeAdd 1000000000 $i]; ::if {![::info exists RecordArray($RecordNumber)]} {::break;} ::append Names $RecordArray($RecordNumber); } ::set Pointers ""; ::for {set i 50} {$i<=52} {::incr i} { ::set RecordNumber [largeAdd 1000000000 $i]; ::if {![::info exists RecordArray($RecordNumber)]} {::break;} ::append Pointers $RecordArray($RecordNumber); } ::if {[::string length $Names]!=[::expr [::string length $Pointers]*10]} { import_error "CONVERT_NV1_TO_NV2 Error in saved settings Names/Pointers for procedure $Procedure"; } ::for {set i 0;set j 0;} {$i<[::string length $Pointers]} {::incr i 3;::incr j 30;} { ::set BaseRecord [::string trimright [::string range $Pointers $i [::expr $i+2]]]; ::if {$BaseRecord==""} {::break} ::set BaseRecord "1$BaseRecord"; ::append BaseRecord "000000"; ::set Name [::string trimright [::string range $Names $j [::expr $j+29]]] ::lappend SettingsList [::list $Name $BaseRecord]; } ::set ResultIndex 0; ::foreach NamedSetting $SettingsList { ::set SettingName [::lindex $NamedSetting 0]; ::set BaseRecord [::lindex $NamedSetting 1]; ::set ResultItem [::list ".name" $SettingName]; ::foreach Item $_procedureRecordArray($Procedure) { ::foreach {Name Record Start Length} $Item {}; ::lappend ResultItem $Name; ::set RecordNumber [largeAdd $BaseRecord $Record]; ::if {[::info exists RecordArray($RecordNumber)]} { ::set Value [::string range $RecordArray($RecordNumber) $Start [::expr $Start+$Length-1]]; ::set Value [::string trimleft [::string trimright $Value]]; } else { ::set Value ""; } ::lappend ResultItem $Value; } ::set Result($ResultIndex) $ResultItem; ::incr ResultIndex; } ::return [::array get Result]; } method buildArrays {} { ::set _procedureRecordArray(NVEXPORT-base) "1000000"; ::set _procedureRecordArray(NVEXPORT) { {.journalReport 0 0 10} {.exportPath 1 0 30} } ::set _procedureRecordArray(APPLY-base) "1"; ::set _procedureRecordArray(APPLY) { {.holdText 0 0 10} {.banks 0 10 30} } ::set _procedureRecordArray(APPLYREF-base) "1"; ::set _procedureRecordArray(APPLYREF) { {.holdText 0 0 10} {.banks 0 10 30} } ::set _procedureRecordArray(COMPANY-base) "1000000"; ::set _procedureRecordArray(COMPANY) { {.companyName 0 0 35} {.companyAddress1 0 35 35} {.companyAddress2 0 70 35} {.companyAddress3 1 0 35} {.companyAddress4 1 35 35} {.companyAddress5 1 70 35} {.companyPhone 1 105 14} {.companyFax 2 0 14} } ::set _procedureRecordArray(FKEYS-base) "1000"; ::set _procedureRecordArray(FKEYS) { {.F1 0 0 0} {.F2 0 0 10} {.F3 0 10 10} {.F4 0 20 10} {.F5 0 30 10} {.F6 0 40 10} {.F7 0 50 10} {.F8 0 60 10} {.F9 0 70 10} {.F10 0 80 10} {.shiftF1 0 90 10} {.shiftF2 0 100 10} {.shiftF3 0 110 10} {.shiftF4 0 120 10} {.shiftF5 1 0 10} {.shiftF6 1 10 10} {.shiftF7 1 20 10} {.shiftF8 1 30 10} {.shiftF9 1 40 10} {.shiftF10 1 50 10} {.ctrlF1 1 60 10} {.ctrlF2 1 70 10} {.ctrlF3 1 80 10} {.ctrlF4 1 90 10} {.ctrlF5 1 100 10} {.ctrlF6 1 110 10} {.ctrlF7 1 120 10} {.ctrlF8 2 0 10} {.ctrlF9 2 10 10} {.ctrlF10 2 20 10} {.altF1 2 30 10} {.altF2 2 40 10} {.altF3 2 50 10} {.altF4 2 60 10} {.altF5 2 70 10} {.altF6 2 80 10} {.altF7 2 90 10} {.altF8 2 100 10} {.altF9 2 110 10} {.altF10 2 120 10} } ::set _procedureRecordArray(GSTPAY) { {.accountNumber 0 0 12} {.periodFrom 0 12 8} {.periodTo 0 20 8} {.dueDate 0 28 8} {.totalSuppliesAccount 0 36 10} {.totalTaxableExpensesAccount 0 46 10} {.totalInventoryAccount 0 56 10} {.GSTCollectibleAccount 0 66 10} {.GSTCollectibleAdjustmentsAccount 0 76 10} {.inputtaxCreditAccount 0 86 10} {.inputtaxCreditAdjustmentAccount 0 96 10} {.installmentsAccount 0 106 10} {.rebatesAccount 0 116 10} {.templateName 1 0 10} {.printer 1 10 10} } ::set _procedureRecordArray(GSTPAY-base) "1000000"; ::set _procedureRecordArray(PRTSTMTS) { {.statementDate 0 0 8} {.days1 0 8 3} {.message1 0 11 49} {.days2 0 60 3} {.message2 0 63 49} {.days3 0 112 3} {.message3 1 0 49} {.message4 1 49 49} {.pagePause 1 98 1} {.skipMinimumBalance 1 99 14} {.boolean 1 113 3} {.skipMinimumAge 1 116 3} {.template 1 119 10} {.printer 2 0 10} } ::set _procedureRecordArray(PRTSTMTS-base) "1000000"; ::array set ProcRecords {}; ::if {[procedureExists "SETUPP"]} { ::array set ProcRecords [procedureRecords "SETUPP"]; } ::set RecordLength 0; ::if {[::info exists ProcRecords(1)]} {::set RecordLength [::string length $ProcRecords(1)];} ::if {$RecordLength<80} { ::set Unique { {.trade_tax/1.expense_or_refund_account 0 0 10} {.trade_tax/1.description 0 10 30} {.trade_tax/1.rate 0 40 5} {.trade_tax/1.is_charged 0 45 1} {.trade_tax/1.otherAccountPrefix 0 46 3} {.trade_tax/1.is_included_in_cost 0 49 1} {.trade_tax/2.expense_or_refund_account 0 50 10} {.trade_tax/2.description 0 60 30} {.trade_tax/2.rate 0 90 5} {.trade_tax/2.is_charged 0 95 1} {.trade_tax/2.otherAccountPrefix 0 96 3} {.trade_tax/2.is_included_in_cost 0 99 1} {.trade_tax/2.is_compounded 0 100 1} {.trade_tax.processed_indicator 0 101 1} } } else { ::set Unique { {.trade_tax/1.expense_or_refund_account 0 0 10} {.trade_tax/1.description 0 10 30} {.trade_tax/1.rate 0 40 5} {.trade_tax/3.rate 0 45 5} {.trade_tax/1.is_charged 0 50 3} {.trade_tax/1.OtherAccountPrefix 0 53 3} {.trade_tax/1.is_included_in_cost 0 56 1} {.trade_tax/2.expense_or_refund_account 0 57 10} {.trade_tax/2.description 0 67 30} {.trade_tax/2.rate 0 97 5} {.trade_tax/2.is_charged 0 102 1} {.trade_tax/2.OtherAccountPrefix 0 103 3} {.trade_tax/2.is_included_in_cost 0 106 1} {.trade_tax/2.is_compounded 0 107 1} {.trade_tax.processed_indicator 0 108 1} } } ::unset ProcRecords; ::set Common { {.purchase_journals 1 0 30} {.banks 1 30 30} {.terms.discount_days 1 60 3} {.terms.discount_rate 1 63 5} {.terms.due_days 1 68 3} } ::set _procedureRecordArray(SETUPP) [::concat $Common $Unique]; ::set _procedureRecordArray(SETUPP-base) "1000000"; ::array set ProcRecords {}; ::if {[procedureExists "SETUPS"]} { ::array set ProcRecords [procedureRecords "SETUPS"]; } ::set RecordLength 0; ::if {[::info exists ProcRecords(1)]} {::set RecordLength [::string length $ProcRecords(1)];} ::if {$RecordLength<80} { ::set Unique { {.trade_tax/1.payable_account 0 0 10} {.trade_tax/1.description 0 10 30} {.trade_tax/1.rate 0 40 5} {.trade_tax/1.is_charged 0 45 1} {.trade_tax/1.Prefix 0 46 3} {.trade_tax/2.payable_account 0 49 10} {.trade_tax/2.description 0 59 30} {.trade_tax/2.rate 0 89 5} {.trade_tax/2.is_charged 0 94 1} {.trade_tax/2.Prefix 0 95 3} {.trade_tax/2.is_compounded 0 98 1} {.sales_journals 0 99 30} {.banks 1 0 30} {.ExtendPriceXQuantity 1 30 1} {.PromptForInvoiceInfo 1 31 1} {.terms.discount_days 1 32 3} {.terms.discount_rate 1 35 5} {.terms.due_days 1 40 3} {.terms.interest_rate 1 43 5} } } else { ::set Unique { {.trade_tax/1.payable_account 0 0 10} {.trade_tax/1.description 0 10 30} {.trade_tax/1.rate 0 40 5} {.trade_tax/3.rate 0 45 5} {.trade_tax/1.is_charged 0 50 1} {.trade_tax/1.Prefix 0 51 3} {.trade_tax/2.payable_account 0 54 10} {.trade_tax/2.description 0 64 30} {.trade_tax/2.rate 0 94 5} {.trade_tax/2.is_charged 0 99 1} {.trade_tax/2.Prefix 0 100 3} {.trade_tax/2.is_compounded 0 103 1} {.sales_Journals 1 0 30} {.banks 1 30 30} {.ExtendPriceXQuantity 1 60 1} {.PromptForInvoiceInfo 1 61 1} {.terms.discount_days 1 62 3} {.terms.discount_rate 1 65 5} {.terms.due_days 1 70 3} {.terms.interest_rate 1 73 5} } } ::unset ProcRecords; ::set Common {} ::set _procedureRecordArray(SETUPS) [::concat $Common $Unique]; ::set _procedureRecordArray(SETUPS-base) "1000000"; ::set _procedureRecordArray(SETUPI-base) "1000000"; ::set _procedureRecordArray(SETUPI) { {.prompt1 0 0 15} {.default1 0 15 30} {.prompt2 0 45 15} {.default2 0 60 30} {.prompt3 0 90 15} {.default3 1 0 30} {.prompt4 1 30 15} {.default4 1 45 30} {.prompt5 1 75 15} {.default5 1 90 30} {.prompt6 2 0 15} {.default6 2 15 30} {.prompt7 2 45 15} {.default7 2 60 30} {.prompt8 2 90 15} {.default8 3 0 30} {.prompt9 3 30 15} {.default9 3 45 30} {.prompt10 3 75 15} {.default10 3 90 30} {.prompt11 4 0 15} {.default11 4 15 30} {.prompt12 4 45 15} {.default12 4 60 30} }; ::set _procedureRecordArray(PRTPAY-base) "1000000"; ::set _procedureRecordArray(PRTPAY) { {.payInvoicesDueUpTo 0 0 8} {.dateOfChecks 0 8 8} {.nextCheckNumber 0 16 7} {.bankOrJournalAccount 0 23 10} {.balancingBankAccount 0 33 10} {.discountAccount 0 43 10} {.pagePause 0 53 1} {.suppressPrinting 0 54 1} {.confirmInvoices 0 55 1} {.confirmSuppliers 0 56 1} {.promptForAddresses 0 57 1} {.paymentsOnTerms 0 62 1} {.takeDiscounts 0 63 1} {.holdInvoicesText 0 64 10} {.nameOfTemplate 0 74 10} {.previewMode 0 84 1} {.advanceRefOnVoidChecks 0 85 1} }; ::set _payrollCountry ""; ::set _payrollLibrary ""; ::set _payrollVersion ""; ::set _payrunProcedureName "PAYRUN" ::set _payroll_is_installed 0; ::if {[procedureExists "PAYRUN"]&&[procedureExists "PAYCODE"]} { ::set ProcSource [procedureSource "PAYCODE"]; ::if {$ProcSource ne ""} { ::set String [::lindex [::split $ProcSource \n] 0]; ::set Pos [::string first "@external(library=" $String];# ) (so parenthesis match in the script) ::if {$Pos>=0} { ::incr Pos 18; ::set String [::string range $String $Pos end]; ::set String [::split $String ","]; ::set _payrollLibrary [::lindex $String 0]; ::set _payrollVersion [::lindex [::split [::lindex $String 1] "="] 1]; ::if {$_payrollVersion eq ""||![::string is integer $_payrollVersion]} { ::set _payrollLibrary ""; } } } ::switch -- $_payrollLibrary { "NV1PRCD1" {::set _payrollCountry "CANADA";::set _payrollLibrary "CASH";} "NV1PRCD2" {::set _payrollCountry "CANADA";::set _payrollLibrary "ACCRUAL";} "NV1PRUS1" { ::set _payrollCountry "USA"; ::set _payrollLibrary "CASH"; ::if {$_payrollVersion>=39} {::set _payrunProcedureName "~AYRUN.8";} } "NV1PRUS2" { ::set _payrollCountry "USA"; ::set _payrollLibrary "ACCRUAL"; ::if {$_payrollVersion>=29} {::set _payrunProcedureName "~AYRUN.7";} } default {::set _payrollCountry "";::set _payrollLibrary "";::set _payrollVersion "";} } ::switch -- $_payrollCountry { "CANADA" { ::switch $_payrollLibrary { "CASH" { ::if {$_payrollVersion<=22} { ::set _procedureRecordArray(PAYRUN-base) "1000000"; ::set _procedureRecordArray(PAYRUN) { {.payrollCheckDate 0 0 8} {.nextCheckNumber 0 8 7} {.timeOnNotesView 0 15 1} {.confirmPayStubs 0 16 1} {.payrollRecordsReport 0 17 10} {.bankOrJournalAccount 0 27 10} {.balancingBankAccount 0 37 10} {.defaultEarningsSuffix 0 47 10} {.employerEiExpenseAccount 0 57 10} {.employerEiAccruedAccount 0 67 10} {.employerCPPExpenseAccount 0 77 10} {.employerCPPAccruedAccount 0 87 10} {.EIEarningsSuffix 0 0 0} {.totalInsurableEarningsAccount 0 0 0} {.EIHoursSuffix 0 0 0} {.totalInsurableHoursAccount 0 0 0} {.CPPEarningsSuffix 1 0 0} {.totalPensionableEarningsAccount 0 0 0} {.taxTable 0 97 10} {.employerPPIPExpenseAccount 0 0 0} {.employerPPIPAccruedAccount 0 0 0} {.PPIPEarningsSuffix 0 0 0} {.totalPPIPInsurableEarningsAccount 0 0 0} } } else { ::set _procedureRecordArray(PAYRUN-base) "1000000"; ::set _procedureRecordArray(PAYRUN) { {.payrollCheckDate 0 0 8} {.nextCheckNumber 0 8 7} {.timeOnNotesView 0 15 1} {.confirmPayStubs 0 16 1} {.payrollRecordsReport 0 17 10} {.bankOrJournalAccount 0 27 10} {.balancingBankAccount 0 37 10} {.defaultEarningsSuffix 0 47 10} {.employerEiExpenseAccount 0 57 10} {.employerEiAccruedAccount 0 67 10} {.employerCPPExpenseAccount 0 77 10} {.employerCPPAccruedAccount 0 87 10} {.EIEarningsSuffix 0 97 10} {.totalInsurableEarningsAccount 0 107 10} {.EIHoursSuffix 0 117 10} {.totalInsurableHoursAccount 1 0 10} {.CPPEarningsSuffix 1 10 10} {.totalPensionableEarningsAccount 1 20 10} {.taxTable 1 30 10} {.employerPPIPExpenseAccount 2 0 10} {.employerPPIPAccruedAccount 3 0 10} {.PPIPEarningsSuffix 4 0 10} {.totalPPIPInsurableEarningsAccount 5 0 10} } } } "ACCRUAL" { ::if {$_payrollVersion<=12} { ::set _procedureRecordArray(PAYRUN-base) "1000000"; ::set _procedureRecordArray(PAYRUN) { {.payrollCheckDate 0 0 8} {.nextCheckNumber 0 8 7} {.timeOnNotesView 0 15 1} {.confirmPayStubs 0 16 1} {.payrollRecordsReport 0 17 10} {.bankOrJournalAccount 0 27 10} {.balancingBankAccount 0 37 10} {.defaultEarningsSuffix 0 47 10} {.employerEiExpenseAccount 0 57 10} {.employerEiAccruedAccount 0 67 10} {.employerCPPExpenseAccount 0 77 10} {.employerCPPAccruedAccount 0 87 10} {.EIEarningsSuffix 0 97 10} {.totalInsurableEarningsAccount 0 107 10} {.EIHoursSuffix 0 0 0} {.totalInsurableHoursAccount 0 0 0} {.CPPEarningsSuffix 0 117 10} {.totalPensionableEarningsAccount 1 0 10} {.taxTable 1 10 10} {.employerPPIPExpenseAccount 0 0 0} {.employerPPIPAccruedAccount 0 0 0} {.PPIPEarningsSuffix 0 0 0} {.totalPPIPInsurableEarningsAccount 0 0 0} } } else { ::set _procedureRecordArray(PAYRUN-base) "1000000"; ::set _procedureRecordArray(PAYRUN) { {.payrollCheckDate 0 0 8} {.nextCheckNumber 0 8 7} {.timeOnNotesView 0 15 1} {.confirmPayStubs 0 16 1} {.payrollRecordsReport 0 17 10} {.bankOrJournalAccount 0 27 10} {.balancingBankAccount 0 37 10} {.defaultEarningsSuffix 0 47 10} {.employerEiExpenseAccount 0 57 10} {.employerEiAccruedAccount 0 67 10} {.employerCPPExpenseAccount 0 77 10} {.employerCPPAccruedAccount 0 87 10} {.EIEarningsSuffix 0 97 10} {.totalInsurableEarningsAccount 0 107 10} {.EIHoursSuffix 0 117 10} {.totalInsurableHoursAccount 1 0 10} {.CPPEarningsSuffix 1 10 10} {.totalPensionableEarningsAccount 1 20 10} {.taxTable 1 30 10} {.employerPPIPExpenseAccount 2 0 10} {.employerPPIPAccruedAccount 3 0 10} {.PPIPEarningsSuffix 4 0 10} {.totalPPIPInsurableEarningsAccount 5 0 10} } } } } ::set _procedureRecordArray(SETUPQ-base) "1000000"; ::set _procedureRecordArray(SETUPQ) { {.employerHSFAccruedAccount 0 0 10} {.employerHSFExpenseAccount 1 0 10} {.HSFEarningsSuffix 2 0 8} {.totalHSFEarningsAccount 3 0 10} {.employerHSFContributionRate 4 0 6} } ::set _procedureRecordArray(T4PREP-base) "1000000"; ::set _procedureRecordArray(T4PREP) { {.yearEndingDate 0 0 8} {.payrollRecordsReport 1 0 10} {.defaultEarningsSuffix 2 0 10} {.provincialJurisdiction 3 0 2} {.pensionPlanRegistrationNumber 4 0 10} {.businessNumber 5 0 15} {.EIEarningsSuffix 6 0 10} {.CPPEarningsSuffix 8 0 10} {.EmployerName 9 0 30} {.EmployerAddress1 10 0 30} {.EmployerAddress2 11 0 30} {.EmployerAddress3 12 0 30} {.EmployerAddress4 13 0 30} } ::set _procedureRecordArray(R1PREP-base) "1000000"; ::set _procedureRecordArray(R1PREP) { {.yearEndingDate 0 0 8} {.payrollRecordsReport 1 0 10} {.defaultEarningsSuffix 2 0 10} {.accountNumber 5 0 12} {.QPPEarningsSuffix 8 0 10} {.HSFEarningsSuffix 9 0 10} {.EmployerName 10 0 30} {.EmployerAddress1 11 0 30} {.EmployerAddress2 12 0 30} {.EmployerAddress3 13 0 30} {.EmployerAddress4 14 0 30} } ::set _procedureRecordArray(PAYWITH-base) "1000000"; ::set _procedureRecordArray(PAYWITH) { {.payWithholdingUpTo 0 0 8} {.dateOfCheck 0 8 8} {.checkNumber 0 16 7} {.payToTheOrderOf 0 23 30} {.payrollWithholdingsReport 0 53 10} {.bankOrJournalAccount 0 63 10} {.balancingBankAccount 0 73 10} } ::set _procedureRecordArray(PAYWITH2-base) "1000000"; ::set _procedureRecordArray(PAYWITH2) { {.dateOfCheque 0 0 8} {.Reference 1 0 7} {.payWithholdingsFrom 2 0 8} {.payWithholdingsTo 3 0 8} {.bankOrJournalAccount 4 0 10} {.balancingBankAccount 5 0 10} {.description 6 0 30} {.description1 7 0 30} {.withheldAccount1 8 0 10} {.remittedAccount1 9 0 10} {.description2 10 0 30} {.withheldAccount2 11 0 10} {.remittedAccount2 12 0 10} {.description3 13 0 30} {.withheldAccount3 14 0 10} {.remittedAccount3 15 0 10} {.description4 16 0 30} {.withheldAccount4 17 0 10} {.remittedAccount4 18 0 10} {.description5 19 0 30} {.withheldAccount5 20 0 10} {.remittedAccount5 21 0 10} } ::if {$_payrollVersion<=12} { ::set _procedureRecordArray(TCPROCES-base) "1000000"; ::set _procedureRecordArray(TCPROCES) { {.timeCardBeginDate 0 0 8} {.timeCardEndDate 0 8 8} {.payPeriodBeginDate 0 16 8} {.payPeriodEndDate 0 24 8} {.accruedWagesPayableReport 0 32 10} {.defaultEarningsSuffix 0 42 10} {.employerEIExpenseAccount 0 52 10} {.employerEIAccruedAccount 0 62 10} {.employerCPPExpenseAccount 0 72 10} {.employerCPPAccruedAccount 0 82 10} {.EIEarningsSuffix 0 92 10} {.totalInsurableEarningsAccount 0 102 10} {.EIHoursSuffix 0 0 0} {.totalInsurableHoursAccount 0 0 0} {.CPPEarningsSuffix 0 112 10} {.totalPensionableEarningsAccount 0 122 10} {.taxTable 1 0 10} }; } else { ::set _procedureRecordArray(TCPROCES-base) "1000000"; ::set _procedureRecordArray(TCPROCES) { {.timeCardBeginDate 0 0 8} {.timeCardEndDate 0 8 8} {.payPeriodBeginDate 0 16 8} {.payPeriodEndDate 0 24 8} {.accruedWagesPayableReport 0 32 10} {.defaultEarningsSuffix 0 42 10} {.employerEIExpenseAccount 0 52 10} {.employerEIAccruedAccount 0 62 10} {.employerCPPExpenseAccount 0 72 10} {.employerCPPAccruedAccount 0 82 10} {.EIEarningsSuffix 0 92 10} {.totalInsurableEarningsAccount 0 102 10} {.EIHoursSuffix 0 112 10} {.totalInsurableHoursAccount 1 0 10} {.CPPEarningsSuffix 1 10 10} {.totalPensionableEarningsAccount 1 20 10} {.taxTable 1 30 10} }; } ::set _procedureRecordArray(TCDOMANY-base) "1000000"; ::set _procedureRecordArray(TCDOMANY) { {.timeCardBeginDate 0 0 8} {.timeCardEndDate 0 8 8} {.accruedWagesPayableReport 0 16 10} {.timeCardJournal 0 26 10} {.defaultEarningsSuffix 0 36 10} {.processTimeCards 0 46 1} {.useTimeCardJournalref 0 49 1} } ::set _accountRecordsArray(EMPLOYEE-base) 2000000; ::set _accountRecordsArray(EMPLOYEE) { {.employee_name.last 0 0 20} {.employee_name.first 1 0 20} {.employee_name.middle 2 0 1} {.address.street 3 0 30} {.address.street2 4 0 30} {.address.city 5 0 18} {.address.state 6 0 2} {.address.zipcode 7 0 7} {.address.phone.freeform 8 0 14} {.address.email 9 0 29} {.address.phone/emergency.freeform 10 0 14} {.emergency_contact 11 0 29} {.social_insurance_number 12 0 9} {.date_of_birth 13 0 8} {.sex 14 0 1} {.marital_status 15 0 7} {.first_day_worked 16 0 8} {.occupation 17 0 25} {.last_day_worked 18 0 8} {.termination_code 30 0 1} {.other_information 20 0 32} {.other_information 21 0 32} {.other_information 22 0 32} {.other_information 23 0 32} {.other_information 24 0 32} {.termination_comments/1.text 31 0 35} {.termination_comments/2.text 32 0 35} {.termination_comments/3.text 33 0 35} {.termination_comments/4.text 34 0 35} {.termination_comments/5.text 35 0 35} }; } "USA" { ::set _procedureRecordArray(~AYRUN.8-base) "1000000"; ::set _procedureRecordArray(~AYRUN.8) { {.payrollCheckDate 0 0 3} {.nextCheckNumber 0 8 8} {.timeOnNotesView 0 15 7} {.confirmPaystubs 0 16 10} {.payrollRecordsReport 0 17 10} {.bankOrJournalAccount 0 27 10} {.balancingBankAccount 0 37 10} {.defaultEarningsSuffix 0 47 10} {.employerFICAExpenseAccount 0 57 10} {.employerFICAAccruedAccount 0 67 10} {.employerMEDIExpenseAccount 0 77 10} {.employerMEDIAccruedAccount 0 87 10} {.employerFUTAExpenseAccount 0 97 10} {.employerFUTAAccruedAccount 0 107 10} {.supplementalWageTaxRate 0 117 2} {.taxTable 0 119 10} } ::lappend _procedureRecordArray(~AYRUN.8) {.employeeFUTASuffix 0 0 0} ::lappend _procedureRecordArray(~AYRUN.8) {.totalFUTAEarningsAccount 0 0 0}; ::set _procedureRecordArray(~AYRUN.7-base) "1000000"; ::set _procedureRecordArray(~AYRUN.7) { {.payrollCheckDate 0 0 3} {.nextCheckNumber 0 8 8} {.timeOnNotesView 0 15 7} {.confirmPaystubs 0 16 10} {.payrollRecordsReport 0 17 10} {.bankOrJournalAccount 0 27 10} {.balancingBankAccount 0 37 10} {.defaultEarningsSuffix 0 47 10} {.employerFICAExpenseAccount 0 57 10} {.employerFICAAccruedAccount 0 67 10} {.employerMEDIExpenseAccount 0 77 10} {.employerMEDIAccruedAccount 0 87 10} {.employerFUTAExpenseAccount 0 97 10} {.employerFUTAAccruedAccount 0 107 10} {.employeeFUTASuffix 0 117 10} {.totalFUTAEarningsAccount 1 0 10} {.supplementalWageTaxRate 1 10 2} {.taxTable 1 12 10} } ::if {$_payrollLibrary eq "CASH" && $_payrollVersion<39} { ::set _procedureRecordArray(PAYRUN-base) $_procedureRecordArray(~AYRUN.7-base); ::set _procedureRecordArray(PAYRUN) $_procedureRecordArray(~AYRUN.7); } ::if {$_payrollLibrary eq "ACCRUAL" && $_payrollVersion<29} { ::set _procedureRecordArray(PAYRUN-base) $_procedureRecordArray(~AYRUN.8-base); ::set _procedureRecordArray(PAYRUN) $_procedureRecordArray(~AYRUN.8); } ::set _procedureRecordArray(TCPROCES-base) "1000000"; ::set _procedureRecordArray(TCPROCES) { {.timeCardBeginDate 0 0 8} {.timeCardEndDate 0 8 8} {.payPeriodBeginDate 0 16 8} {.payPeriodEndDate 0 24 8} {.accruedWagesPayableReport 0 32 10} {.defaultEarningsSuffix 0 42 10} {.employerFICAExpenseAccount 0 52 10} {.employerFICAAccruedAccount 0 62 10} {.employerMEDIExpenseAccount 0 72 10} {.employerMEDIAccruedAccount 0 82 10} {.employerFUTAExpenseAccount 0 92 10} {.employerFUTAAccruedAccount 0 102 10} {.employeeFUTASuffix 0 112 10} {.totalFUTAEarningsAccount 1 0 10} {.supplementalWageTaxRate 1 10 2} {.taxTable 1 12 10} }; ::set _procedureRecordArray(W2PREP-base) "1000000"; ::set _procedureRecordArray(W2PREP) { {.yearEndingDate 100 0 8} {.payrollRecordsReport 101 0 10} {.defaultEarningsSuffix 102 0 10} {.startingControlNumber 103 0 7} {.federalId 104 0 12} {.stateId 105 0 12} {.state 106 0 2} {.localJurisdiction 107 0 10} {.tipsSuffix 108 0 8} {.box13DefaultStatutoryEmployee 109 0 1} {.box13DefaultRetirementPlan 110 0 1} {.box13DefaultThirdPartySickPay 111 0 1} {.employerName 112 0 30} {.employerAddress1 113 0 30} {.employerAddress2 114 0 30} {.employerAddress3 115 0 30} {.employerAddress4 116 0 30} } ::set _procedureRecordArray(PAY1099-base) "1000000"; ::set _procedureRecordArray(PAY1099) { {.quarterBeginDate 0 0 8} {.payrollRecordsReports 0 8 30} } ::set _procedureRecordArray(TCDOMANY-base) "1000000"; ::set _procedureRecordArray(TCDOMANY) { {.timeCardBeginDate 0 0 8} {.timeCardEndDate 0 8 8} {.accruedWagesPayableReport 0 16 10} {.timeCardJournal 0 26 10} {.defaultEarningsSuffix 0 36 10} {.processTimeCards 0 46 1} {.useTimeCardJournalref 0 49 1} } ::set _accountRecordsArray(EMPLOYEE-base) 2000000; ::set _accountRecordsArray(EMPLOYEE) { {.employee_name.last 0 0 20} {.employee_name.first 1 0 20} {.employee_name.middle 2 0 1} {.address.street 3 0 30} {.address.street2 4 0 30} {.address.city 5 0 18} {.address.state 6 0 2} {.address.zipcode 7 0 10} {.address.phone.area_code 8 0 3} {.address.phone.prefix 9 0 4} {.address.phone.suffix 10 0 4} {.address.email 11 0 29} {.address.phone/emergency.area_code 12 0 3} {.address.phone/emergency.prefix 13 0 4} {.address.phone/emergency.suffix 14 0 4} {.emergency_contact 15 0 29} {.social_security_number 16 0 9} {.date_of_birth 17 0 8} {.sex 18 0 1} {.marital_status 19 0 7} {.first_day_worked 20 0 8} {.last_day_worked 21 0 8} {.occupation 22 0 25} } } } ::if {$_payrollCountry ne ""} { ::set _payroll_is_installed 1; ::array set Result [procedureSettingsParse $_payrunProcedureName [procedureRecords $_payrunProcedureName]]; ::array set _payrunFieldsArray $Result(0); ::if {$_payrollCountry eq "CANADA"} { ::set Jurisdiction [validate ".province_of_employment" [::string range $_payrunFieldsArray(.taxTable) 1 2]]; ::if {$Jurisdiction eq ""} {::set Jurisdiction "ON";} ::set _payrunFieldsArray(.province_of_employment) $Jurisdiction; } else { ::set Jurisdiction [validate ".state_jurisdiction" [::string range $_payrunFieldsArray(.taxTable) 1 2]]; ::set _payrunFieldsArray(.state_jurisdiction) $Jurisdiction; } ::set _awReportList [payrollInfoLoad ".accruedWagesPayableReport"]; ::array set _payrollSuffixArray {}; ::if {$_payrollCountry eq "CANADA"} { ::set _payrollSuffixArray(IE) [payrollInfoLoad ".EIEarningsSuffix"]; ::set _payrollSuffixArray(IH) [payrollInfoLoad ".EIHoursSuffix"]; ::set _payrollSuffixArray(PE) [payrollInfoLoad ".CPPEarningsSuffix"]; ::set _payrollSuffixArray(HE) [payrollInfoLoad ".HSFEarningsSuffix"]; ::set _payrollSuffixArray(PI) [payrollInfoLoad ".PPIPEarningsSuffix"]; ::array unset _setupqFieldsArray; ::array set _setupqFieldsArray {}; ::if {[procedureExists "SETUPQ"]} { ::array set Result [procedureSettingsParse "SETUPQ" [procedureRecords "SETUPQ"]]; ::array set _setupqFieldsArray $Result(0); } } ::if {$_payrollCountry eq "USA"} { ::set _payrollSuffixArray(FE) [payrollInfoLoad ".employeeFUTASuffix"]; } } } else { ::set _payroll_is_installed 0; } ::set RecordBase1 0; ::set RecordBase2 0; ::if {[procedureExists "NOTES2"]} { ::set Notes2Notes [procedureNotes "NOTES2"]; ::if {$Notes2Notes ne ""} { ::set Notes2Notes [::split $Notes2Notes]; ::set Note0 [::string toupper [::lindex $Notes2Notes 0]]; ::if {[::string range $Note0 0 12]=="@RECORDBASE1="} { ::set RecordBase1 [::string range $Note0 13 end]; ::if {![isInteger $RecordBase1]} { ::set RecordBase1 0; } else { ::incr RecordBase1; } } ::set Note1 [::string toupper [::lindex $Notes2Notes 1]]; ::if {[::string range $Note1 0 12]=="@RECORDBASE2="} { ::set RecordBase2 [::string range $Note1 13 end]; ::if {![isInteger $RecordBase2]} { ::set RecordBase2 0; } else { ::incr RecordBase2; } } } } ::set _accountRecordsArray(AP-base) $RecordBase1; ::set _accountRecordsArray(AP) { {.address.name.salutation 0 0 3} {.address.name.first 1 0 29} {.address.name.middle 2 0 1} {.address.name.last 3 0 29} {.address.company 4 0 41} {.address.street 5 0 41} {.address.city 6 0 25} {.address.state 7 0 2} {.address.zipcode 8 0 10} {.address.country 9 0 20} {.address.phone.country_code 10 0 7} {.address.phone.area_code 11 0 3} {.address.phone.prefix 12 0 4} {.address.phone.suffix 13 0 6} {.address.phone.extension 14 0 5} {.address.phone/fax.country_code 15 0 7} {.address.phone/fax.area_code 16 0 3} {.address.phone/fax.prefix 17 0 4} {.address.phone/fax.suffix 18 0 6} {.address.phone/fax.extension 19 0 5} } ::set _accountRecordsArray(AR-base) $RecordBase2; ::set _accountRecordsArray(AR) { {.address.name.salutation 0 0 3} {.address.name.first 1 0 29} {.address.name.middle 2 0 1} {.address.name.last 3 0 29} {.address.company 4 0 41} {.address.street 5 0 41} {.address.city 6 0 25} {.address.state 7 0 2} {.address.zipcode 8 0 10} {.address.country 9 0 20} {.address.phone.country_code 10 0 7} {.address.phone.area_code 11 0 3} {.address.phone.prefix 12 0 4} {.address.phone.suffix 13 0 6} {.address.phone.extension 14 0 5} {.address.phone/fax.country_code 15 0 7} {.address.phone/fax.area_code 16 0 3} {.address.phone/fax.prefix 17 0 4} {.address.phone/fax.suffix 18 0 6} {.address.phone/fax.extension 19 0 5} {.address/shipping.name.salutation 30 0 3} {.address/shipping.name.first 31 0 29} {.address/shipping.name.middle 32 0 1} {.address/shipping.name.last 33 0 29} {.address/shipping.company 34 0 41} {.address/shipping.street 35 0 41} {.address/shipping.city 36 0 25} {.address/shipping.state 37 0 2} {.address/shipping.zipcode 38 0 10} {.address/shipping.country 39 0 20} {.address/shipping.phone.country_code 40 0 7} {.address/shipping.phone.area_code 41 0 3} {.address/shipping.phone.prefix 42 0 4} {.address/shipping.phone.suffix 43 0 6} {.address/shipping.phone.extension 44 0 5} {.address/shipping.phone/fax.country_code 45 0 7} {.address/shipping.phone/fax.area_code 46 0 3} {.address/shipping.phone/fax.prefix 47 0 4} {.address/shipping.phone/fax.suffix 48 0 6} {.address/shipping.phone/fax.extension 49 0 5} } ::array set _accountNotesArray {}; ::set _accountNotesArray(AP) { {.address1 0 0 35} {.address2 1 0 35} {.address3 2 0 35} {.address4 3 0 35} {.address5 4 0 35} {.address6 5 0 35} {.address7 6 0 35} {.address8 7 0 35} {.address.phone.freeform 10 0 15} {.address.phone/fax.freeform 9 0 15} {.terms.discount_days 8 0 3} {.terms.due_days 8 8 3} {.terms.discount_rate 8 3 5} {.trade_tax/1.is_charged 11 0 1} {.trade_tax/2.is_charged 12 0 1} {.trade_tax/1.is_included_in_cost 13 0 1} {.trade_tax/2.is_included_in_cost 14 0 1} {.trade_tax/1.registration_id 8 11 10} {.trade_tax/2.registration_id 8 21 10} }; ::set _accountNotesArray(AR) { {.address1 0 0 35} {.address2 1 0 35} {.address3 2 0 35} {.address4 3 0 35} {.address5 4 0 35} {.address6 5 0 35} {.address7 6 0 35} {.address8 7 0 35} {.shipAddress1 0 40 35} {.shipAddress2 1 40 35} {.shipAddress3 2 40 35} {.shipAddress4 3 40 35} {.shipAddress5 4 40 35} {.shipAddress6 5 40 35} {.shipAddress7 6 40 35} {.shipAddress8 7 40 35} {.address.phone.freeform 8 0 15} {.address.phone/fax.freeform 9 0 15} {.terms.discount_days 12 0 3} {.terms.discount_rate 12 3 5} {.terms.due_days 12 8 3} {.terms.interest_rate 12 11 5} {.trade_tax/1.is_charged 10 0 1} {.trade_tax/2.is_charged 11 0 1} }; ::set _accountNotesArray(INVENTORY) { {.description 0 0 30} {.trade_tax/1.expense_or_refund_account 2 0 10} {.trade_tax/1.description 3 0 30} {.trade_tax/1.rate 1 0 5} {.trade_tax/3.rate 1 5 5} {.trade_tax/2.expense_or_refund_account 5 0 10} {.trade_tax/2.description 6 0 30} {.trade_tax/2.rate 4 0 5} }; ::set _accountNotesArray(EXPENSE) { {.description 0 0 30} {.trade_tax/1.expense_or_refund_account 2 0 10} {.trade_tax/1.description 3 0 30} {.trade_tax/1.rate 1 0 5} {.trade_tax/3.rate 1 5 5} {.trade_tax/2.expense_or_refund_account 5 0 10} {.trade_tax/2.description 6 0 30} {.trade_tax/2.rate 4 0 5} }; ::set _accountNotesArray(CGS) { }; ::set _accountNotesArray(SALES) { {.description1 0 0 30} {.description2 0 30 30} {.description3 0 60 30} {.description4 0 90 30} {.description5 1 30 30} {.description6 1 60 30} {.description7 1 90 30} {.description8 2 30 30} {.price 1 0 14} {.trade_tax/1.payable_account 3 0 10} {.trade_tax/1.description 4 0 30} {.trade_tax/1.rate 2 0 5} {.trade_tax/3.rate 2 5 5} {.trade_tax/2.payable_account 5 5 10} {.trade_tax/2.description 5 15 30} {.trade_tax/2.rate 5 0 5} }; ::if {[procedureExists "NOTES"]} { ::if {[procedureRecords "NOTES"]!=""} { ::array set _accountClass [class_array_create [procedureRecords "NOTES"]]; } } } public method payrollInfoLoad {Src} { ::set Result ""; ::set ProcedureList ""; ::foreach ProcedureName [::array names _procedureRecordArray] { ::if {[::string first "-base" $ProcedureName]!=-1} {::continue;} ::if {![procedureExists $ProcedureName]} {::continue;} ::foreach Item $_procedureRecordArray($ProcedureName) { ::if {[::lindex $Item 0]==$Src} { ::catch {::unset Results;} ::array set Results [procedureSettingsParse $ProcedureName [procedureRecords $ProcedureName]]; ::foreach ResultItem [::array names Results] { ::array set ResultArray $Results($ResultItem); ::set Value $ResultArray($Src); ::if {$Value==""} {::continue;} ::if {[::lsearch -exact $Result $Value]==-1} {::lappend Result $ResultArray($Src);} } ::break; } } } ::return $Result; } method splitAccountName {Src} { ::set Position 10; ::set Separator ""; ::foreach Char {"." "-" "~"} { ::set i [::string first $Char $Src]; ::if {$i<0||$i>8||$i>$Position} {::continue;} ::set Position $i; } ::if {$Position>8} {::return "";} ::set Separator [::string index $Src $Position]; ::set Prefix [::string range $Src 0 [::expr $Position-1]]; ::set Suffix [::string range $Src [::expr $Position+1] end]; ::if {$Prefix eq ""||$Suffix eq ""} {::return "";} ::return [::list $Prefix $Separator $Suffix]; } public method payrolls_count {args} { ::array set Args $args; ::set EmployeePrefix $Args(.prefix); ::if {$_payrollCountry=="CANADA"} { ::array set EmployeeAccountsArray {"D=EI:" {} "D=UIC:" {} "D=CPP:" {} "D=QPP:" {} "D=TAX:" {}}; ::set EIContributionRate 1.4; } ::if {$_payrollCountry=="USA"} { ::array set EmployeeAccountsArray {"D=FICA:" {} "D=MEDI:" {} "D=FIT:" {}}; ::set EIContributionRate 1; } ::foreach Account $Args(.accounts) { ::array set Details $Account; ::if {$Details(.normal_balance)!="credit"} {::continue;} ::foreach Code [::array names EmployeeAccountsArray] { ::if {[::string first $Code $Details(.description)]<0} {::continue;} ::if {$Details(.totalTo1)!=""} { ::if {[::lindex [splitAccountName $Details(.totalTo1)] 0]!=$EmployeePrefix} { ::set EmployeeAccountsArray($Code) $Details(.totalTo1); } } ::if {$Details(.totalTo2)!=""} { ::if {[::lindex [splitAccountName $Details(.totalTo2)] 0]!=$EmployeePrefix} { ::set EmployeeAccountsArray($Code) $Details(.totalTo2); } } ::if {$Code=="D=UIC:"||$Code=="D=EI:"} { ::if {[::string first "%=" $Details(.description)]>=0} { ::array unset _payCodesArray; setPayCodes $Details(.description); ::set Rate [payCodeValue "%"]; ::if {$Rate!=""&&[::string is double $Rate]} { ::set EIContributionRate $Rate; } } } } } ::if {$_payrollCountry=="CANADA"} { ::if {$EmployeeAccountsArray(D=UIC:)!=""&&$EmployeeAccountsArray(D=EI:)==""} { ::set EmployeeAccountsArray(D=EI:) $EmployeeAccountsArray(D=UIC:); } ::unset EmployeeAccountsArray(D=UIC:); } ::set isMatch 0; ::for {::set i 0;} {$i<[::llength $_payroll_list]} {::incr i;} { ::set Payroll [::lindex $_payroll_list $i]; ::array set PayrollDetails $Payroll; ::array set EmployerAccountsArray $PayrollDetails(.accounts); ::if {$PayrollDetails(.reportName)!=$Args(.reportName)} {::continue;} ::if {$_payrollCountry=="CANADA"} {::set EmployerEIContributionRate $PayrollDetails(.eiRate);} ::set isMatch 1; ::foreach {Code Account} [::array get EmployeeAccountsArray] { ::if {$Account!=""} { ::if {$EmployerAccountsArray($Code)!=""} { ::if {$Account!=$EmployerAccountsArray($Code)} { ::set isMatch 0; ::break; } } else { ::set EmployerAccountsArray($Code) $Account; } } } ::if {$PayrollDetails(.accrual) ne $Args(.accrual)} {::set isMatch 0;} ::if {$PayrollDetails(.payPeriods) ne $Args(.payPeriods)} {::set isMatch 0;} ::if {$_payrollCountry=="CANADA"} { ::if {$PayrollDetails(.eiRate) ne $EIContributionRate} {::set isMatch 0;} } ::if {$isMatch} {::break;} } ::if {$isMatch} { ::set PayrollDetails(.accounts) [::array get EmployerAccountsArray]; ::set Payroll [::array get PayrollDetails]; ::set _payroll_list [::lreplace $_payroll_list $i $i $Payroll]; } else { ::catch {::unset PayrollDetails}; ::set PayrollDetails(.accrual) $Args(.accrual); ::set PayrollDetails(.accounts) [::array get EmployeeAccountsArray]; ::set PayrollDetails(.eiRate) $EIContributionRate; ::set PayrollDetails(.payPeriods) $Args(.payPeriods); ::set PayrollDetails(.reportName) $Args(.reportName); ::set PayrollDetails(.reportDescription) $Args(.reportDescription); ::lappend _payroll_list [::array get PayrollDetails]; increment "payrolls-target"; } ::return $i; } method accountOdbAddressFromName {Src} { ::if {$Src eq ""} {::return "";} ::set Src [stringFilter $Src]; ::set Class $_account_class_array($Src); ::if {$Class eq "PAYROLL"} {::set Class "PAYROLL/$_payrollCountry";} ::set Result [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/$Class$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Src]; ::if {$Result eq ""} { import_error "Failed to find account $Src"; } ::return [[$Result odb_master] odb_address]; } method payrolls_create {} { ::if {$_payrolls_have_been_processed} {::return $this;} ::array set EiRatesArray {}; ::foreach Payroll $_payroll_list { ::array set PayrollDetails $Payroll; ::set EiRatesArray($PayrollDetails(.eiRate)) ""; } ::set NewList ""; ::foreach Payroll $_payroll_list { ::array set PayrollDetails $Payroll; ::set PayrollDetails(.path) ""; ::set PayrollDetails(.name) ""; ::set PayrollDetails(.description) ""; ::if {[::llength [::array names EiRatesArray]]>1} { ::lappend PayrollDetails(.path) [::list "EI" [::string map {. _} $PayrollDetails(.eiRate)]]; } ::lappend PayrollDetails(.path) [::list "REPORT" [::list $PayrollDetails(.reportName) $PayrollDetails(.reportDescription)]]; ::lappend NewList [::array get PayrollDetails]; } ::set _payroll_list $NewList; ::unset EiRatesArray; ::array set PayPeriodsArray {}; ::set Flag 0; ::foreach Payroll $_payroll_list { ::array set PayrollDetails $Payroll; ::set ReportName $PayrollDetails(.reportName); ::set PayPeriods $PayrollDetails(.payPeriods); ::if {![::info exists PayPeriodsArray($ReportName)]} { ::set PayPeriodsArray($ReportName) ""; } ::if {[::lsearch -exact $PayPeriodsArray($ReportName) $PayPeriods]<0} { ::lappend PayPeriodsArray($ReportName) $PayPeriods; } ::if {[::llength $PayPeriodsArray($ReportName)]>1} {::set Flag 1;} } ::if {$Flag} { ::set NewList ""; ::foreach Payroll $_payroll_list { ::array set PayrollDetails $Payroll; ::set ReportName $PayrollDetails(.reportName); ::lappend PayrollDetails(.path) [::list "PP" $PayrollDetails(.payPeriods)]; ::lappend NewList [::array get PayrollDetails]; } ::set _payroll_list $NewList; } ::unset PayPeriodsArray; ::array set PayTypesArray {}; ::set Flag 0; ::foreach Payroll $_payroll_list { ::array set PayrollDetails $Payroll; ::set ReportName $PayrollDetails(.reportName); ::if {![::info exists PayTypesArray($ReportName-accrual)]} { ::set PayTypesArray($ReportName-accrual) 0; ::set PayTypesArray($ReportName-cash) 0; } ::if {$PayrollDetails(.accrual)} { ::set PayTypesArray($ReportName-accrual) 1; } else { ::set PayTypesArray($ReportName-cash) 1; } ::if {$PayTypesArray($ReportName-accrual)&&$PayTypesArray($ReportName-cash)} {::set Flag 1;} } ::if {$Flag} { ::set NewList ""; ::foreach Payroll $_payroll_list { ::array set PayrollDetails $Payroll; ::set ReportName $PayrollDetails(.reportName); ::if {$PayTypesArray($ReportName-accrual)&&$PayTypesArray($ReportName-cash)} { ::if {$PayrollDetails(.accrual)} { ::lappend PayrollDetails(.path) [::list "TYPE" "ACCRUAL"]; } else { ::lappend PayrollDetails(.path) [::list "TYPE" "CASH"]; } } ::lappend NewList [::array get PayrollDetails]; } ::set _payroll_list $NewList; } ::unset PayTypesArray; ::array set PathArray {}; ::set PathList ""; ::set NewList ""; ::if {[::llength $_payroll_list]>0} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "EMPLOYEES"]; ::if {$Reference ne ""} { [$Reference odb_master] odb_destroy; } } ::append _payroll_convert_notes "CREATING PAYROLLS\n"; ::foreach Payroll $_payroll_list { ::array set PayrollDetails $Payroll; ::set Components $PayrollDetails(.path); ::set Path ""; ::set Name ""; ::set Description ""; ::foreach Component $Components { ::foreach {Item Value} $Component {}; ::switch -- $Item { "EI" { ::append Path "/EI$Value"; ::append Name "_EI-$Value"; ::set Description "E.I. Rate $Value%"; } "REPORT" { ::append Path "/[::lindex $Value 0]"; ::append Name "_[::lindex $Value 0]"; ::set Description "[::lindex $Value 1]"; } "PP" { ::append Path "/$Value";::append Path "PP"; ::append Name "_$Value PP"; ::set Description "[payFrequencyDescription $Value]"; } "TYPE" { ::append Path "/$Value"; ::append Name "_$Value"; ::set Description "[::string totitle $Value]"; } } ::set Name [::join [::split $Name] "_"]; ::set Path [::string trimleft $Path "/"]; ::if {![::info exists PathArray($Path)]} { ::if {[::llength [::split $Path "/"]] eq 1} { ::set Object [[$_manager "/OBJECT/NEWVIEWS/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds"] odb_factory]; } else { ::set Parent [::join [::lrange [::split $Path "/"] 0 end-1] "/"]; ::set ParentObject $PathArray($Parent); ::set Object [[$ParentObject ".odb_deriveds"] odb_factory]; } [$Object ".name"] odb_set [::string toupper $Name]; [$Object ".description"] odb_set $Description; [$Object ".pay_frequency"] odb_set $PayrollDetails(.payPeriods); ::if {$_payrollCountry=="CANADA"} { [$Object ".ei_contribution_rate"] odb_set $PayrollDetails(.eiRate); [$Object ".cpp_contribution_rate"] odb_set "1"; ::if {[procedureExists "SETUPQ"]} { [$Object ".hsf_contribution_rate"] odb_set $_setupqFieldsArray(.employerHSFContributionRate); } } else { ::if {[procedureExists "~US.TBL"]} { ::if {[::string first "@ROUND" [::lindex [procedureNotes "~US.TBL"] 0]]>=0} { [$Object ".round_federal_tax"] odb_set "yes"; } } [$Object ".social_security_contribution_rate"] odb_set 1.0; [$Object ".medicare_contribution_rate"] odb_set 1.0; [$Object ".futa_contribution_rate"] odb_set 0.008; } ::set Notes " Name: [::string toupper $Name] Desc: $Description Pay Freq: $PayrollDetails(.payPeriods)"; ::if {$_payrollCountry=="CANADA"} { ::append Notes " EI Rate: $PayrollDetails(.eiRate) CPP Rate: 1\n"; } else { ::append Notes " SS Rate: 1.0 Medicare Rate: 1 FUTA Rate: 0.08\n"; } ::append _payroll_convert_notes $Notes; commit $Object; ::set PathArray($Path) $Object; } } status "Payroll: $Name"; increment "payrolls-processed"; ::set Address [$Object odb_address]; ::set PayrollDetails(.payroll) $Address; ::lappend NewList [::array get PayrollDetails]; abort_check; } ::switch -- $_payrollCountry { "CANADA" { [$_manager "/OBJECT/NEWVIEWS/PAYROLL/${_payrollCountry}.default_province"] odb_set $_payrunFieldsArray(.province_of_employment); } "USA" { } } ::set _payroll_list $NewList; ::set _payrolls_have_been_processed 1; ::append _payroll_convert_notes "\n"; ::return $this; } method payruns_create {} { ::if {$_payruns_have_been_processed} {::return $this;} ::set Notes [procedureNotes "PAYRUN"]; ::foreach String {"@DEL<0" "@DEL<=0" "@DEL=0"} { ::if {[::string first $String $Notes]<0} {::continue;} ::set Master [$_manager "/OBJECT/NEWVIEWS/SYSTEM/EMPLOYEE"]; ::switch $String { "@DEL<0" {[$Master ".minimum_check_amount"] odb_set 0.00;} "@DEL=0" - "@DEL<=0" {[$Master ".minimum_check_amount"] odb_set 0.01;} } commit $Master; } ::unset Notes; ::set NewPayrollList ""; ::foreach PayrollItem $_payroll_list { ::array set PayrollDetails $PayrollItem; ::set Payroll $PayrollDetails(.payroll); ::set PayrollId [$Payroll odb_id]; ::set Payrun [$_manager "/OBJECT/NEWVIEWS/SYSTEM/PAYRUN/${_payrollCountry}"]; ::if {$NewPayrollList eq ""} { [$Payrun ".payroll_journal"] odb_set [$_manager "/OBJECT/NEWVIEWS/JOURNAL/PAYROLL/PAYCHECK/$_payrollCountry$_slashIdPrefix"]; ::set Structure ""; ::if {$_payrunFieldsArray(.balancingBankAccount) ne ""} { ::set Account $_payrunFieldsArray(.balancingBankAccount); } else { ::set Account $_payrunFieldsArray(.bankOrJournalAccount); } ::if {[accountExists $Account]} { ::set Address [accountOdbAddressFromName $Account]; ::set Structure [::sargs::set $Structure /bank $Address]; } ::if {$_payrollCountry=="CANADA"} { ::foreach {Nv1Field Nv2Field} { .employerCPPExpenseAccount cpp_expense .employerCPPAccruedAccount cpp_accrued .employerEiExpenseAccount ei_expense .employerEiAccruedAccount ei_accrued .employerPPIPExpenseAccount ppip_expense .employerPPIPAccruedAccount ppip_accrued } { ::if {[accountExists $_payrunFieldsArray($Nv1Field)]} { ::set Address [accountOdbAddressFromName $_payrunFieldsArray($Nv1Field)]; ::set Structure [::sargs::set $Structure "/employer_contribution/$Nv2Field" $Address]; } } ::if {[procedureExists "SETUPQ"]} { ::foreach {Nv1Field Nv2Field} { .employerHSFExpenseAccount hsf_expense .employerHSFAccruedAccount hsf_accrued } { ::if {[accountExists $_setupqFieldsArray($Nv1Field)]} { ::set Address [accountOdbAddressFromName $_setupqFieldsArray($Nv1Field)]; ::set Structure [::sargs::set $Structure "/employer_contribution/$Nv2Field" $Address]; } } } } ::if {$_payrollCountry=="USA"} { ::foreach {Nv1Field Nv2Field} { .employerFICAExpenseAccount social_security_expense .employerFICAAccruedAccount social_security_accrued .employerMEDIExpenseAccount medicare_expense .employerMEDIAccruedAccount medicare_accrued .employerFUTAExpenseAccount futa_expense .employerFUTAAccruedAccount futa_accrued } { ::if {[accountExists $_payrunFieldsArray($Nv1Field)]} { ::set Address [accountOdbAddressFromName $_payrunFieldsArray($Nv1Field)]; ::set Structure [::sargs::set $Structure "/employer_contribution/$Nv2Field" $Address]; } } } [$Payrun ".accounts"] odb_set $Structure; } ::set PayrollDetails(.payrun) [$Payrun odb_address]; ::set PayrollItem [::array get PayrollDetails]; ::lappend NewPayrollList [$Payroll odb_path]; commit $Payrun; abort_check; } ::set _payroll_list $NewPayrollList; ::set _payruns_have_been_processed 1; ::return $this; } method payFrequencyDescription {Src} { ::switch -exact $Src { "1" {::return "Annual";} "12" {::return "Monthly";} "24" {::return "Semi-Monthly";} "26" {::return "Bi-Weekly";} "52" {::return "Weekly";} default {::return "$Src Pay Periods";} } } method isAccrualEmployee {EmployeeAccounts} { ::foreach Account $EmployeeAccounts { ::array set AccountDetails $Account; ::if {[::lindex [splitAccountName $AccountDetails(.name)] 1]=="~"} {::return 1;} } ::return 0; } method employees_count {} { ::if {$_employees_have_been_counted} {::return $this;} ::set _employee_list ""; ::if {!$_payroll_is_installed} { ::set _employees_have_been_counted 1; ::set _payrolls_have_been_processed 1; ::set _payruns_have_been_processed 1; ::return $this; } status "Counting payroll items..."; ::set RegAccountSuffix $_payrunFieldsArray(.defaultEarningsSuffix); #// What if it's null?!? ::set EmployeeName ""; ::set CurrentPrefix ""; ::set Separator ""; ::set LastGoodPayFrequencyValue ""; ::array set EmployeeArray {}; ::set EmployeeAccounts ""; ::set EmployeeTextLines ""; ::set IsEmployee 0; ::set ReportIndex [$_manager "/OBJECT/NEWVIEWS/REPORT$_slashIdPrefix.odb_deriveds.index/name"]; ::for {::set ReportRef [$ReportIndex odb_first];} {$ReportRef!=""} {::set ReportRef [$ReportIndex odb_next $ReportRef];} { ::set ReportName [[[$ReportRef odb_master] ".name"] qw_get]; ::set ReportDescription [[[$ReportRef odb_master] ".description"] qw_get]; ::set AccountsIndex [[[$ReportRef odb_master] ".accounts"] ".index/interactive"]; ::set AccountRef [$AccountsIndex odb_first]; ::while {$AccountRef!=""} { ::set Account [$AccountRef odb_master]; abort_check; ::set AccountRef [$AccountsIndex odb_next $AccountRef]; ::set AccountName [[$Account ".name"] qw_get]; ::if {$AccountName==""} {::continue;} status "Searching for employees, Account: $AccountName"; ::set TotalTo1 [[$Account ".total.parent1"] qw_get]; ::set TotalTo2 [[$Account ".total.parent2"] qw_get]; ::if {[[$Account ".total.kids"] odb_items]!=0} { ::set IsTotalAccount 1; } else { ::set IsTotalAccount 0; } ::set AccountNameItems [splitAccountName $AccountName]; ::set AccountPrefix [::lindex $AccountNameItems 0]; ::set AccountSeparator [::lindex $AccountNameItems 1]; ::set AccountSuffix [::lindex $AccountNameItems 2]; ::if {$AccountPrefix==""||$AccountSeparator==""||$AccountSuffix==""} {::continue;} ::if {$Separator eq ""} { ::if {$AccountSeparator eq "."||$AccountSeparator eq "-"} { ::set Separator $AccountSeparator; } } ::set AccountDescription [[$Account ".description"] qw_get] ::set AccountDescription [::string trimleft $AccountDescription "~"]; ::set AccountDescription [::string trimright $AccountDescription]; ::set AccountNormalBalance [$Account normal_balance_get]; ::if {$AccountNormalBalance eq "debit"} {::set Type "EARNING";} else {::set Type "DEDUCTION";}; ::if {$TotalTo1 ne ""} {::set TotalTo1 [[[$TotalTo1 odb_master] ".name"] qw_get];} ::if {$TotalTo2 ne ""} {::set TotalTo2 [[[$TotalTo2 odb_master] ".name"] qw_get];} ::while {[::string index $AccountDescription end]=="/"} { ::set AccountDescription [::string trimright $AccountDescription "/ "]; ::set NextAccount [$AccountRef odb_master]; ::set NextAccountName [[$NextAccount ".name"] qw_get]; ::if {$NextAccountName!=""} {::break;} ::set NextAccountDescription [[$NextAccount ".description"] qw_get]; ::set NextAccountDescription [::string trimleft $NextAccountDescription "~"]; ::set NextAccountDescription [::string trimright $NextAccountDescription]; ::append AccountDescription $NextAccountDescription; ::lappend EmployeeTextLines [$NextAccount odb_address]; ::set AccountRef [$AccountsIndex odb_next $AccountRef]; } ::if {$AccountPrefix ne $CurrentPrefix} { ::if {$IsEmployee&&$Separator ne ""} { ::unset -nocomplain Fields;::array set Fields {}; ::set RegAccount [employeeRegAccount $EmployeeAccounts]; ::set EmployeeArray(.regAccount) ""; ::if {$RegAccount ne ""} { ::set EmployeeArray(.regAccount) [[$RegAccount ".name"] odb_get]; ::set EmployeeName ""; ::array set Fields [records_fields_extract $RegAccount "EMPLOYEE"]; ::if {[::info exists Fields(.employee_name.last)]} {::append EmployeeName "$Fields(.employee_name.last),";} ::if {[::info exists Fields(.employee_name.first)]} {::append EmployeeName " $Fields(.employee_name.first)";} ::if {[::info exists Fields(.employee_name.middle)]} {::append EmployeeName " $Fields(.employee_name.middle)";} ::set EmployeeName [::string trim $EmployeeName]; ::set EmployeeArray(.name) $EmployeeName; } ::set Status $EmployeeName; ::if {$Status eq ""} {::set Status $CurrentPrefix;} ::set EmployeeArray(.text_lines) $EmployeeTextLines; ::set EmployeeArray(.records_fields) [::array get Fields]; ::set EmployeeArray(.separator) $Separator; ::set EmployeeArray(.accounts) $EmployeeAccounts; ::set EmployeeArray(.other_accounts) [otherEmployeeAccounts .prefix $CurrentPrefix .separator $Separator]; ::set EmployeeArray(.accounts) [payrollSetupFix1 $EmployeeArray(.accounts) $EmployeeArray(.other_accounts)]; ::array set EmployeeArray [::eval payrollSetupFix2 [::array get EmployeeArray]]; ::set EmployeeArray(.accrual) [isAccrualEmployee $EmployeeAccounts]; ::set EmployeeArray(.payroll) [::eval payrolls_count [::array get EmployeeArray]]; ::eval dumpEmployeeAccounts [::array get EmployeeArray]; ::eval employeeAccountsMark [::array get EmployeeArray]; ::lappend _employee_list [::array get EmployeeArray]; increment "employees-target"; ::set RegAccount ""; ::set EmployeeName ""; ::set EmployeeTextLines ""; } ::set CurrentPrefix $AccountPrefix; ::unset EmployeeArray; ::set EmployeeArray(.prefix) $CurrentPrefix; ::set EmployeeArray(.name) ""; ::set EmployeeArray(.regAccount) ""; ::set EmployeeArray(.separator) ""; ::set EmployeeArray(.reportName) $ReportName; ::set EmployeeArray(.reportDescription) $ReportDescription; ::set EmployeeArray(.accounts) ""; ::set EmployeeArray(.other_accounts) ""; ::set EmployeeArray(.quebec) 0; ::set EmployeeArray(.accrual) 0; ::set EmployeeArray(.payPeriods) 0; ::set EmployeeAccounts ""; ::set IsEmployee 0; ::set Separator ""; } ::lappend EmployeeAccounts [::list \ .name $AccountName \ .master $Account \ .address [$Account odb_address] \ .normal_balance $AccountNormalBalance \ .description $AccountDescription \ .totalTo1 $TotalTo1 \ .totalTo2 $TotalTo2 \ .isTotalAccount $IsTotalAccount \ .type $Type \ .suffix $AccountSuffix \ ]; ::array unset _payCodesArray; setPayCodes $AccountDescription; ::if {!$EmployeeArray(.quebec)} { ::if {[payCodeValue "J"] eq "PQ"||[payCodeValue "J"] eq "QT"||[payCodeValue "D"] eq "QTAX"||[payCodeValue "D"] eq "QPP"||[payCodeValue "E"] eq "Q"} { ::set EmployeeArray(.quebec) 1; } } ::if {$IsEmployee} {::continue;} ::if {[payCodeExists "P"]} { ::set PayPeriods [payCodeValue "P"]; ::if {$PayPeriods==""} {::continue;} ::if {![::string is integer $PayPeriods]} {::continue;} ::if {$PayPeriods<=0} {::continue;} ::if {[::lsearch "1 4 12 13 24 26 52" $PayPeriods]<0} { ::if {$LastGoodPayFrequencyValue eq ""} {::continue;} ::set PayPeriods $LastGoodPayFrequencyValue; } else { ::set LastGoodPayFrequencyValue $PayPeriods; } ::set EmployeeArray(.payPeriods) $PayPeriods; ::set IsEmployee 1; } } } ::if {$IsEmployee&&$Separator!=""} { ::unset -nocomplain Fields;::array set Fields {}; ::set RegAccount [employeeRegAccount $EmployeeAccounts]; ::set EmployeeArray(.regAccount) ""; ::if {$RegAccount ne ""} { ::set EmployeeArray(.regAccount) [[$RegAccount ".name"] odb_get]; ::set EmployeeName ""; ::array set Fields [records_fields_extract $RegAccount "EMPLOYEE"]; ::if {[::info exists Fields(.employee_name.last)]} {::append EmployeeName "$Fields(.employee_name.last),";} ::if {[::info exists Fields(.employee_name.first)]} {::append EmployeeName " $Fields(.employee_name.first)";} ::if {[::info exists Fields(.employee_name.middle)]} {::append EmployeeName " $Fields(.employee_name.middle)";} ::set EmployeeName [::string trim $EmployeeName]; ::set EmployeeArray(.name) $EmployeeName; } ::set Status $EmployeeName; ::if {$Status eq ""} {::set Status $CurrentPrefix;} ::set EmployeeArray(.text_lines) $EmployeeTextLines; ::set EmployeeArray(.records_fields) [::array get Fields]; ::set EmployeeArray(.separator) $Separator; ::set EmployeeArray(.accounts) $EmployeeAccounts; ::set EmployeeArray(.other_accounts) [otherEmployeeAccounts .prefix $CurrentPrefix .separator $Separator]; ::set EmployeeArray(.accounts) [payrollSetupFix1 $EmployeeArray(.accounts) $EmployeeArray(.other_accounts)]; ::array set EmployeeArray [::eval payrollSetupFix2 [::array get EmployeeArray]]; ::set EmployeeArray(.accrual) [isAccrualEmployee $EmployeeAccounts]; ::set EmployeeArray(.payroll) [::eval payrolls_count [::array get EmployeeArray]]; ::eval dumpEmployeeAccounts [::array get EmployeeArray]; ::eval employeeAccountsMark [::array get EmployeeArray]; ::lappend _employee_list [::array get EmployeeArray]; increment "employees-target"; } markGovernmentTotalsAccounts; ::set _employees_have_been_counted 1; ::if {[::llength $_employee_list]} { payroll_sanity_check; ;#// check for impossible settings from payroll procedures check_payroll_accounts; } } method payroll_sanity_check {} { ::if {!$_payroll_is_installed} {::return $this;} ::set ErrorList ""; ::array set MultipleSuffixEmployees {}; ::set MultipleSuffixErrors ""; ::set AccountConflictErrors ""; ::set MultipleGTErrors ""; ::array set PayrunSettingsArray [procedureSettingsParse $_payrunProcedureName [procedureRecords $_payrunProcedureName]]; ::array set TcprocesSettingsArray {}; ::if {[procedureExists "TCPROCES"]} { ::array set TcprocesSettingsArray [procedureSettingsParse "TCPROCES" [procedureRecords "TCPROCES"]]; } ::array set SetupqSettingsArray {}; ::if {[procedureExists "SETUPQ"]} { ::array set SetupqSettingsArray [procedureSettingsParse "SETUPQ" [procedureRecords "SETUPQ"]]; } ::array set T4PrepSettingsArray {}; ::if {[procedureExists "T4PREP"]} { ::array set T4PrepSettingsArray [procedureSettingsParse "T4PREP" [procedureRecords "T4PREP"]]; } ::foreach {Suffix TextName} { .EIEarningsSuffix "EI Earnings" .EIHoursSuffix "EI Hours" .CPPEarningsSuffix "CPP Earnings" .employeeFUTASuffix "FUTA earnings" } { ::set SuffixList ""; ::set NameList ""; ::set ProcList ""; ::array unset Settings; ::foreach Procedure { Payrun Tcproces Setupq T4Prep } { ::if {![procedureExists [::string toupper $Procedure]]} {::continue;} ::for {::set i 0} {$i<=100} {::incr i;} { ::if {![::info exists [::subst ${Procedure}SettingsArray($i)]]} {::break;} ::array set Settings [::subst $${Procedure}SettingsArray($i)]; ::if {![::info exists Settings($Suffix)]} {::continue;} ::if {$Settings($Suffix) eq ""} {::continue;} ::set Setting $Settings($Suffix); ::if {[::lsearch -exact $SuffixList $Setting]>=0} {::continue;} ::lappend SuffixList $Setting; ::lappend NameList $Settings(.name); ::lappend ProcList [::string toupper $Procedure]; } } ::if {[::llength $SuffixList]>1} { ::set Error ""; ::lappend Error "[::llength $SuffixList] different $TextName account suffixes found in payroll procedure settings."; ::foreach Suffix $SuffixList ProcName $ProcList SettingsName $NameList { ::if {$SettingsName eq ""} { ::lappend Error " $TextName suffix is set to '$Suffix' in procedure $ProcName, default settings."; } else { ::lappend Error " $TextName suffix is set to '$Suffix' in procedure $ProcName, named setting '$SettingsName'."; } } ::lappend MultipleSuffixErrors $Error; } } ::append _payroll_convert_notes "\n[::llength $_employee_list] EMPLOYEES FOUND IN NV1 BOOKS\n"; ::foreach Employee $_employee_list { ::array set EmployeeArray $Employee; ::set EmployeePrefix $EmployeeArray(.prefix); ::set EmployeeAccounts ""; ::foreach Item $EmployeeArray(.accounts) { ::array set ItemArray $Item; ::lappend EmployeeAccounts $ItemArray(.name); } ::foreach Item $EmployeeArray(.other_accounts) { ::array set ItemArray $Item; ::lappend EmployeeAccounts $ItemArray(.name); } ::set GTCount [::llength $EmployeeArray(.other_accounts)]; ::if {$_payrollCountry eq "USA" && $_payrollLibrary eq "CASH"} { ::append _payroll_convert_notes " $EmployeePrefix\n"; } else { ::if {$GTCount!=0} { ::append _payroll_convert_notes " $EmployeePrefix\n"; } else { ::append _payroll_convert_notes "* $EmployeePrefix - no GT accounts found\n"; } } ::for {::set i 0} {$i<=100} {::incr i;} { ::if {![::info exists PayrunSettingsArray($i)]} {::break;} ::array set PayrunSettings $PayrunSettingsArray($i); ::foreach {GTAccount TextName} { .totalInsurableEarningsAccount "Total EI earnings" .totalInsurableHoursAccount "Total EI hours" .totalPensionableEarningsAccount "Total CPP earnings" .totalFUTAEarningsAccount "Total FUTA earnings" } { ::if {![::info exists PayrunSettings($GTAccount)]} {::continue;} ::set GTAccountName $PayrunSettings($GTAccount); ::if {$GTAccountName eq ""} {::continue;} ::if {[::lsearch -exact $EmployeeAccounts $GTAccountName]>=0} { ::set SettingsName $PayrunSettings(.name); ::set Error "In the procedure PAYRUN, the \"$TextName\" account is set to employee $EmployeePrefix account $GTAccountName"; ::if {$SettingsName ne ""} { ::append Error " in named settings \"$SettingsName\""; } ::lappend AccountConflictErrors $Error; } } } ::for {::set i 0} {$i<=100} {::incr i;} { ::if {![::info exists TcprocesSettingsArray($i)]} {::break;} ::array set TcprocesSettings $TcprocesSettingsArray($i); ::foreach {GTAccount TextName} { .totalInsurableEarningsAccount "Total EI earnings" .totalInsurableHoursAccount "Total EI hours" .totalPensionableEarningsAccount "Total CPP earnings" .totalFUTAEarningsAccount "Total FUTA earnings" } { ::if {![::info exists TcprocesSettings($GTAccount)]} {::continue;} ::set GTAccountName $TcprocesSettings($GTAccount); ::if {$GTAccountName eq ""} {::continue;} ::if {[::lsearch -exact $EmployeeAccounts $GTAccountName]>=0} { ::set SettingsName $TcprocesSettings(.name); ::set Error "In the procedure TCPROCES, the \"$TextName\" account is set to employee $EmployeePrefix account $GTAccountName"; ::if {$SettingsName ne ""} { ::append Error " in named settings \"$SettingsName\""; } ::lappend AccountConflictErrors $Error; } } } ::for {::set i 0} {$i<=100} {::incr i;} { ::if {![::info exists SetupqSettingsArray($i)]} {::break;} ::array set SetupqSettings $SetupqSettingsArray($i); ::foreach {GTAccount TextName} { .employerHSFAccruedAccount "Employer HSF accrued" .employerHSFExpenseAccount "Employer HSF expense" .totalHSFEarningsAccount "Total HSF earnings" } { ::if {![::info exists SetupqSettings($GTAccount)]} {::continue;} ::set GTAccountName $SetupqSettings($GTAccount); ::if {$GTAccountName eq ""} {::continue;} ::if {[::lsearch -exact $EmployeeAccounts $GTAccountName]>=0} { ::set SettingsName $SetupqSettings(.name); ::set Error "In the procedure SETUPQ, the \"$TextName\" account is set to employee $EmployeePrefix account $GTAccountName"; ::if {$SettingsName ne ""} { ::append Error " in named settings \"$SettingsName\""; } ::lappend AccountConflictErrors $Error; } } } ::array unset TypeArray; ::foreach Item $EmployeeArray(.other_accounts) { ::array set ItemArray $Item; ::set Type $ItemArray(.type); ::if {![::info exists TypeArray($Type)]} {::set TypeArray($Type) "";} ::lappend TypeArray($Type) $ItemArray(.name); } ::foreach Type [::array names TypeArray] { ::if {[::llength $TypeArray($Type)]==1} {::continue;} ::switch $Type { "IE" {::set Name "EI insurable earnings"} "IH" {::set Name "EI insurable hours"} "PE" {::set Name "CPP pensionable earnings"} "HE" {::set Name "H.S.F. earnings"} "FE" {::set Name "F.U.T.A. earnings"} default {::qw::bug "20040523184423" "Unknown other account type \"$Type\" found in employee $EmployeePrefix accounts.";} } ::set Error "Employee $EmployeePrefix appears to have [::llength $TypeArray($Type)] $Name accounts: $TypeArray($Type)"; ::lappend MultipleGTErrors $Error; ::set MultipleSuffixEmployees($EmployeePrefix) 1; } } ::append _payroll_convert_notes "\n"; ::set TotalErrorCount [::expr [::llength $MultipleGTErrors]+[::llength $AccountConflictErrors]]; ::set DuplicateIdErrors ""; ::array unset EmployeePrefixArray; ::array set EmployeePrefixArray {}; ::foreach Employee $_employee_list { ::array unset EmployeeArray; ::array set EmployeeArray $Employee; ::set EmployeePrefix $EmployeeArray(.prefix); ::set EmployeeRegAccount $EmployeeArray(.regAccount); ::lappend EmployeePrefixArray($EmployeePrefix) $EmployeeRegAccount; } ::foreach {EmployeePrefix RegAccountList} [::array get EmployeePrefixArray] { ::if {[::llength $RegAccountList]>1} { ::set Error "[::llength $RegAccountList] employees with the prefix $EmployeePrefix found. Their regular earnings accounts are"; ::if {[::llength $RegAccountList]>2} {::set Comma ","} else {::set Comma "";} ::foreach AccountName [::lrange $RegAccountList 0 end-1] { ::append Error " $AccountName$Comma"; } ::append Error " and [::lindex $RegAccountList end]."; ::lappend DuplicateIdErrors $Error; } } ::set CrossLinkedAccountErrors "";; ::array unset WhateverArray; ::array set WhateverArray {}; ::foreach Employee $_employee_list { ::array unset EmployeeArray; ::array set EmployeeArray $Employee; ::set EmployeePrefix $EmployeeArray(.prefix); ::set EmployeeRegAccount $EmployeeArray(.regAccount); ::set EmployeeAccounts ""; ::foreach Item $EmployeeArray(.other_accounts) { ::array unset ItemArray; ::array set ItemArray $Item; ::lappend WhateverArray($ItemArray(.name)) $EmployeePrefix; } } ::foreach {OtherAccount PrefixList} [::array get WhateverArray] { ::if {[::llength $PrefixList]>1} { ::set Error "Employee account $OtherAccount appears to belong to [::llength $PrefixList] employees whose regular earnings accounts are"; ::set RegAccounts ""; ::foreach Prefix $PrefixList { ::foreach RegAccount $EmployeePrefixArray($Prefix) { ::set RegAccounts [::qw::union $RegAccounts [::list $RegAccount]]; } } ::if {[::llength $RegAccounts]==1} { ::append Error " [::lindex $RegAccounts 0]."; } else { ::if {[::llength $RegAccounts]>2} {::set Comma ","} else {::set Comma "";} ::foreach AccountName [::lrange $RegAccounts 0 end-1] { ::append Error " $AccountName$Comma"; } ::append Error " and [::lindex $RegAccounts end]."; } ::lappend CrossLinkedAccountErrors $Error; } } ::set TotalErrorCount [::expr $TotalErrorCount+[::llength $CrossLinkedAccountErrors]]; ::if {$TotalErrorCount==0} {::return $this;} ::set FileName [::file join $_database_directory "PayrollErrors.txt"]; ::set Handle [::open $FileName w]; ::set ErrorMessage "$TotalErrorCount errors encountered while creating employees."; ::puts $Handle $ErrorMessage\n; control_message_send "*USER_MESSAGE* $ErrorMessage"; ::puts $Handle "Errors:"; control_message_send "*USER_MESSAGE* Errors:"; ::foreach Error $AccountConflictErrors { ::puts $Handle " $Error"; control_message_send "*USER_MESSAGE* $Error"; } ::if {$MultipleGTErrors ne ""} { ::foreach Error $MultipleGTErrors { ::puts $Handle " $Error"; control_message_send "*USER_MESSAGE* $Error"; } ::if {$MultipleSuffixErrors ne ""} { ::puts $Handle "Probable reason(s)"; control_message_send "*USER_MESSAGE* Probable reason(s)"; ::foreach Error $MultipleSuffixErrors { ::puts $Handle " [::lindex $Error 0]"; control_message_send "*USER_MESSAGE* [::lindex $Error 0]"; ::foreach Line [::lrange $Error 1 end] { ::puts $Handle " $Line"; control_message_send "*USER_MESSAGE* $Line"; } } } } ::if {$CrossLinkedAccountErrors ne ""} { ::foreach Error $CrossLinkedAccountErrors { ::puts $Handle " $Error"; control_message_send "*USER_MESSAGE* $Error"; } ::if {$DuplicateIdErrors ne ""} { ::puts $Handle "Probable reason(s)"; control_message_send "*USER_MESSAGE* Probable reason(s)"; ::foreach Error $DuplicateIdErrors { ::puts $Handle " $Error"; control_message_send "*USER_MESSAGE* $Error"; } } } control_message_send "*USER_MESSAGE* (This error list has also been written to the file $FileName)"; ::close $Handle; ::append ErrorMessage " (Click 'Help' for details)"; import_error [::sargs \ .text $ErrorMessage \ .help_id 907020050404084709 \ .multiple_suffix_errors $MultipleSuffixErrors\ .multiple_suffix_employees [::llength [::array names MultipleSuffixEmployees]] \ .account_conflict_errors $AccountConflictErrors \ .multiple_gt_errors $MultipleGTErrors \ .payroll_country $_payrollCountry \ .filename $FileName \ .cross_linked_account_errors [::llength $CrossLinkedAccountErrors] \ .cross_linked_account_error_list $CrossLinkedAccountErrors \ .duplicate_id_errors [::llength $DuplicateIdErrors] \ .duplicate_id_error_list $DuplicateIdErrors \ ]; ::return $this; } method employees_process {} { payrolls_create; payruns_create; ::if {![::llength $_employee_list]} {::set _employees_have_been_processed 1;} ::if {$_employees_have_been_processed} {::return $this;} ::append _payroll_convert_notes "CREATING EMPLOYEES\n"; ::while {1} { ::eval employeeCreate [::eval check_payroll_accounts_class [::lindex $_employee_list 0]]; ::set _employee_list [::lreplace $_employee_list 0 0]; increment "employees-processed"; batch_check_employees; ::if {![::llength $_employee_list]} {::break;} } ::set _employees_have_been_processed 1; ::return $this; } public method employeeRegAccount {Accounts} { ::set RegAccountSuffix $_payrunFieldsArray(.defaultEarningsSuffix); #// What if it's null?!? ::foreach AccountItem $Accounts { ::array set AccountArray $AccountItem; ::set AccountName $AccountArray(.name); ::set AccountNameItems [splitAccountName $AccountName]; ::set AccountSuffix [::lindex [splitAccountName $AccountName] 2]; ::if {$AccountSuffix eq $RegAccountSuffix} { ::return $AccountArray(.master); } } ::array set AccountArray [::lindex $Accounts 0]; ::return $AccountArray(.master); } public method payrollSetupFix1 {Accounts OtherAccounts} { ::set Result ""; ::foreach AccountItem $Accounts { ::array set AccountArray $AccountItem; ::set AccountName $AccountArray(.name); ::set Found 0; ::foreach OtherAccountItem $OtherAccounts { ::array set OtherAccountArray $OtherAccountItem; ::set OtherAccountName $OtherAccountArray(.name); ::if {$AccountName eq $OtherAccountName} {::set Found 1;::break;} } ::if {!$Found} {::lappend Result $AccountItem;} } ::return $Result; } public method payrollSetupFix2 {args} { ::array set Args $args; ::set Accounts ""; ::set TotalAccounts ""; ::foreach Account $Args(.accounts) { ::array set AccountArray $Account; ::set AccountName $AccountArray(.name); ::if {$AccountArray(.isTotalAccount)} { ::lappend TotalAccounts $Account; } ::lappend Accounts $Account; } ::set NetAccount ""; ::foreach TotalAccount $TotalAccounts { ::array set AccountArray $TotalAccount; ::if {$AccountArray(.totalTo1) ne ""} {::continue;} ::if {$AccountArray(.totalTo2) ne ""} {::continue;} ::if {$AccountArray(.normal_balance) ne "debit"} {::continue;} ::set NetAccount $AccountArray(.name); } ::if {$NetAccount ne ""} { ::for {::set i 0;} {$i<[::llength $Accounts]} {::incr i;} { ::array set AccountArray [::lindex $Accounts $i]; ::if {$AccountArray(.name) eq $NetAccount} { ::set AccountArray(.type) "NET"; ::set Accounts [::lreplace $Accounts $i $i [::array get AccountArray]]; ::break; } } } ::set Args(.accounts) $Accounts; ::return [::array get Args]; } public method find_benefits_accounts {Accounts} { ::if {$_payrollCountry ne "CANADA"} {::return "";} ::set TaxSeen 0; ::set EiSeen 0; ::set CppSeen 0; ::set Benefit_Struct ""; ::set PpipSeen 0; ::set OtherAccountsPostingsClosure ""; ::set LocalTotalAccountsPostings ""; ::for {::set i 0} {$i<[::llength $Accounts]} {::incr i;} { ::set AccountItem [::lindex $Accounts $i]; ::array set AccountArray $AccountItem; ::if {$AccountArray(.isTotalAccount)} { ::lappend LocalTotalAccountsPostings [$AccountArray(.master) ".postings"]; ::continue; } ::array unset _payCodesArray; setPayCodes $AccountArray(.description); ::switch -- [payCodeValue "D"] { "EI" {::set EiSeen 1;} "PPIP" {::set PpipSeen 1;} "UIC" {::set EiSeen 1;} "CPP" {::set CppSeen 1;} "QPP" {::set CppSeen 1;} "TAX" {::set TaxSeen 1;} "QTAX" {::set TaxSeen 1;} } ::if {![payCodeExists "B"]} { ::set PostingsClosure [[$AccountArray(.master) ".postings"] odb_closure]; ::set OtherAccountsPostingsClosure [::qw::union $PostingsClosure $OtherAccountsPostingsClosure]; ::continue; } ::foreach {T4_Box Releve1_Box} [translate_benefit_code [payCodeValue "B"]] {}; ::if {$T4_Box eq "" && $Releve1_Box eq ""} {::continue;} ::if {$T4_Box eq "30" || $Releve1_Box eq "H"} {::set EiSeen 0;} else {::set EiSeen 1;} ::sargs::var::set Benefit_Struct /$i.item $i; ::sargs::var::set Benefit_Struct /$i.t4_box $T4_Box; ::sargs::var::set Benefit_Struct /$i.releve1_box $Releve1_Box; ::set Value [payCodeValue "R"]; ::if {![::string is double $Value]&&![::string is integer $Value]} {::set Value 0.0;} ::if {$Value eq ""} {::set Value 0.0;} ::sargs::var::set Benefit_Struct /$i.amount $Value; ::sargs::var::set Benefit_Struct /$i.percent [payCodeValue "%"]; ::sargs::var::set Benefit_Struct /$i.description [payCodeValue "M"]; ::sargs::var::set Benefit_Struct /$i.normal_balance $AccountArray(.normal_balance); ::sargs::var::set Benefit_Struct /$i.name $AccountArray(.name); ::sargs::var::set Benefit_Struct /$i.done 0; ::sargs::var::set Benefit_Struct /$i.taxable [::expr !$TaxSeen]; ::sargs::var::set Benefit_Struct /$i.pensionable [::expr !$CppSeen]; ::sargs::var::set Benefit_Struct /$i.insurable [::expr !$EiSeen]; ::sargs::var::set Benefit_Struct /$i.ppip_insurable [::expr !$PpipSeen]; ::sargs::var::set Benefit_Struct /$i.master $AccountArray(.master); } ::set OtherAccountsPostingsClosure [::lindex [::qw::intersect3 $LocalTotalAccountsPostings $OtherAccountsPostingsClosure] 2]; ::set SubNames [::sargs::subs .structure $Benefit_Struct]; ::foreach SubName $SubNames { ::set Account [::sargs::get $Benefit_Struct $SubName.master]; ::set PostingsClosure [[$Account ".postings"] odb_closure]; ::set IntersectResult [::qw::intersect3 $PostingsClosure $OtherAccountsPostingsClosure]; ::foreach Item [::lindex $IntersectResult 1] { ::if {[[$Item odb_master] odb_is_class]} { ::continue; } ::sargs::var::unset Benefit_Struct $SubName; ::break; } } ::if {[::llength [::sargs::subs .structure $Benefit_Struct]]<2} {::return "";} ::set Count 0; ::set Result ""; ::set SubNames [::sargs::subs .structure $Benefit_Struct]; ::set Found 0; ::foreach SubName1 $SubNames { ::set Sub1 [::sargs::get $Benefit_Struct $SubName1]; ::if {[::sargs::get $Sub1 ".done"]} {::continue;} ::foreach SubName2 $SubNames { ::if {$SubName1 eq $SubName2} {::continue;} ::set Sub2 [::sargs::get $Benefit_Struct $SubName2]; ::if {[::sargs::get $Sub2 ".done"]} {::continue;} ::if {[::sargs::get $Sub1 ".t4_box"] ne [::sargs::get $Sub2 ".t4_box"]} {::continue;} ::if {[::sargs::get $Sub1 ".releve1_box"] ne [::sargs::get $Sub2 ".releve1_box"]} {::continue;} ::if {[::sargs::get $Sub1 ".amount"] ne [::sargs::get $Sub2 ".amount"]} {::continue;} ::if {[::sargs::get $Sub1 ".percent"] ne [::sargs::get $Sub2 ".percent"]} {::continue;} ::if {[::sargs::get $Sub1 ".normal_balance"] eq [::sargs::get $Sub2 ".normal_balance"]} {::continue;} ::if {[::sargs::get $Sub1 ".name"] eq [::sargs::get $Sub2 ".name"]} {import_error "Unknown error locating employee benefits";} ::incr Count; ::sargs::var::set Result /$Count.benefit $Count; ::sargs::var::set Result /$Count.t4_box [::sargs::get $Sub1 ".t4_box"]; ::sargs::var::set Result /$Count.releve1_box [::sargs::get $Sub1 ".releve1_box"]; ::sargs::var::set Result /$Count.amount [::sargs::get $Sub1 ".amount"]; ::sargs::var::set Result /$Count.percent [::sargs::get $Sub1 ".percent"]; ::sargs::var::set Result /$Count.description [::sargs::get $Sub1 ".description"]; ::sargs::var::set Result /$Count.account/[::sargs::get $Sub1 ".normal_balance"] [::sargs::get $Sub1 ".name"]; ::sargs::var::set Result /$Count.account/[::sargs::get $Sub2 ".normal_balance"] [::sargs::get $Sub2 ".name"]; ::sargs::var::set Result /$Count.taxable [::sargs::get $Sub1 ".taxable"]; ::sargs::var::set Result /$Count.pensionable [::sargs::get $Sub1 ".pensionable"]; ::sargs::var::set Result /$Count.insurable [::sargs::get $Sub1 ".insurable"]; ::sargs::var::set Result /$Count.ppip_insurable [::sargs::get $Sub1 ".ppip_insurable"]; ::sargs::var::set Benefit_Struct $SubName1.done 1; ::sargs::var::set Benefit_Struct $SubName2.done 1; ::break; } ::if {$Found} {::break;} } ::if {$Count>4} {import_error "Employee has more than 4 non-cash taxable benefits.";} ::return $Result; } public method translate_benefit_code {Src} { ::if {[::string range $Src 0 1] ne "T4"} {::return [::list "" ""];} ::switch -- [::string range $Src 2 end] { "30" {::return [::list "30" "H"];} "31" {::return [::list "31" ""];} "32" {::return [::list "32" "K"];} "33" {::return [::list "33" ""];} "34" {::return [::list "34" "I"];} "35" {::return [::list "35" ""];} "36" {::return [::list "36" "L"];} "37" {::return [::list "37" ""];} "38" {::return [::list "38" "L"];} "39" {::return [::list "39" ""];} "40" {::return [::list "40" "L"];} "41" {::return [::list "41" ""];} "42" {::return [::list "42" "M"];} "70" {::return [::list "70" ""];} "71" {::return [::list "71" "R"];} "72" {::return [::list "72" ""];} "73" {::return [::list "73" ""];} "74" {::return [::list "74" ""];} "75" {::return [::list "75" ""];} "76" {::return [::list "76" ""];} "H" {::return [::list "30" "H"];} "I" {::return [::list "34" "I"];} "J" {::return [::list "" "J"];} "K" {::return [::list "32" "K"];} "L" {::return [::list "40" "L"];} "M" {::return [::list "42" "M"];} "N" {::return [::list "46" "N"];} "O" {::return [::list "" "O"];} "P" {::return [::list "" "P"];} "Q" {::return [::list "" "Q"];} "R" {::return [::list "71" "R"];} "S" {::return [::list "" "S"];} "T" {::return [::list "14" "T"];} "U" {::return [::list "14" "U"];} default {::return [::list "" ""];} } } public method dumpEmployeeAccounts {args} { puts_rth {"#RTH tdumpEmployeeAccounts start"}; ::array set Args $args; ::foreach {Name Value} [::array get Args] { ::if {$Name eq ".accounts"||$Name eq ".other_accounts"} {::continue;} puts_rth {"\t$Name\t$Value"}; } puts_rth {"\t.accounts:"}; ::foreach AccountItem $Args(.accounts) { ::array set ItemArray $AccountItem; ::foreach {Name Value} [::array get ItemArray] { puts_rth {"\t\t$Name\t$Value"}; } puts_rth {"\t\t-------"}; } puts_rth {"\t.other accounts:"}; ::foreach AccountItem $Args(.other_accounts) { ::array set ItemArray $AccountItem; ::foreach {Name Value} [::array get ItemArray] { puts_rth {"\t\t$Name\t$Value"}; } puts_rth {"\t\t-------"}; } puts_rth {"#RTH tdumpEmployeeAccounts done"}; } public method markGovernmentTotalsAccounts {} { ::if {$_payrollCountry=="CANADA"} { ::set List { {".totalInsurableEarningsAccount" "IE"} {".totalInsurableHoursAccount" "IH"} {".totalPensionableEarningsAccount" "PE"} {".totalHSFEarningsAccount" "HE"} {".totalPPIPInsurableEarningsAccount" "PI"} } } else { ::set List { {".totalFUTAEarningsAccount" "FE"} } } ::foreach Item $List { ::foreach {FieldName Code} $Item {;}; ::set TargetList [payrollInfoLoad $FieldName]; ::foreach Target $TargetList { abort_check; ::if {![accountExists $Target]} {::continue;} ::set Account [account_get $Target]; ::set Import_Datum [[$Account ".import_datum"] qw_get]; ::sargs::var::set Import_Datum ".payroll_class" "PAYROLL/$Code/TOTAL"; ::sargs::var::set Import_Datum ".history_ignore" 1; [$Account ".import_datum"] odb_set $Import_Datum; ::set _account_class_array($Target-payroll_class) "PAYROLL/$Code/TOTAL"; } } } public method otherEmployeeAccounts {args} { ::array set Args $args; ::set Result ""; ::set Prefix [string map {? \\? + \\+ * \\*} $Args(.prefix)]; ::set Accounts [::lsearch -all -inline -regexp [::array names _account_class_array] (^$Prefix)(\[$Args(.separator)||~\])(.+)]; ;#// Yes, it works. ::foreach AccountName $Accounts { ::set SplitName [splitAccountName $AccountName]; ::set Prefix [::lindex $SplitName 0]; ::set Separator [::lindex $SplitName 1]; ::set Suffix [::lindex $SplitName 2]; ::if {$Prefix ne $Args(.prefix)} { ::qw::bug "20040908115225" "Bad account prefix \"$Prefix\" in Account name \"$AccountName\"."; } ::if {$Separator ne "-"&&$Separator ne "."&&$Separator ne "~"} { ::qw::bug "20040908115255" "Bad account separator \"$Separator\"."; } ::if {$Suffix eq ""} {::continue;} ::set Account [account_get $AccountName]; ::set Report [[[[[$Account ".report"] qw_get] odb_master] ".name"] qw_get]; ::array set AccountInfoArray [accountInfoList $Account]; ::if {!$AccountInfoArray(.isTotalAccount)} { ::if {[::lsearch -exact $_awReportList $Report]!=-1} { ::set AccountInfoArray(.type) "AW"; ::lappend Result [::array get AccountInfoArray]; ::continue; } ::foreach SearchItem [::array names _payrollSuffixArray] { ::if {[::lsearch -exact $_payrollSuffixArray($SearchItem) $Suffix]!=-1} { ::set AccountInfoArray(.type) $SearchItem; ::lappend Result [::array get AccountInfoArray]; } } } } ::return $Result; } method accountInfoList {Account} { ::set TotalTo1 [[$Account ".total.parent1"] qw_get]; ::if {$TotalTo1!=""} {::set TotalTo1 [[[$TotalTo1 odb_master] ".name"] qw_get];} ::set TotalTo2 [[$Account ".total.parent2"] qw_get]; ::if {$TotalTo2!=""} {::set TotalTo2 [[[$TotalTo2 odb_master] ".name"] qw_get];} ::if {[[$Account ".total.kids"] odb_items]!=0} { ::set IsTotalAccount 1; } else { ::set IsTotalAccount 0; } ::return [::list \ .name [[$Account ".name"] qw_get] \ .master $Account \ .address [$Account odb_address] \ .normal_balance [$Account normal_balance_get] \ .description [[$Account ".description"] qw_get] \ .totalTo1 $TotalTo1 \ .totalTo2 $TotalTo2 \ .isTotalAccount $IsTotalAccount \ .type "" \ ]; } method setPayCodes {Src} { ::foreach Code [::split $Src ":"] { ::if {$Code eq ""} {::continue;} ::foreach {Name Value} [::split $Code "="] {} ::if {$Name eq ""||$Value eq ""} {::continue;} ::if {[payCodeExists $Name]} {::continue;} payCodeValue $Name $Value; } ::return $this; } method payCodeValue {args} { ::set Name [::lindex $args 0]; ::set Value [::lindex $args 1]; ::switch -- [::llength $args] { 1 { ::if {[payCodeExists $Name]} {::return $_payCodesArray($Name);} ::return ""; } 2 { ::set _payCodesArray($Name) $Value; ::return $this; } default {::error "Wrong number of args to payCodeValue method.";} } } method payCodeValueUcase {Src} { ::return [::string toupper [payCodeValue $Src]]; } method payCodeValueNumber {Src} { ::set Result [payCodeValue $Src]; ::return [[$_manager "/OBJECT/NEWVIEWS/PAYROLL"] npl_string_numeric_value $Result]; } method payCodeValueInteger {Src} { ::return [::expr int([payCodeValueNumber $Src])]; } method payCodeValueBoolean {Src} { ::set Result [payCodeValue $Src]; ::if {![::string is boolean $Result]} {::return 0;} ::if {$Result} {::return 1;} ::return 0; } method payCodeExists {Src} { ::if {![::info exists _payCodesArray($Src)]} {::return 0;} ::if {$_payCodesArray($Src)==""} {::return 0;} ::return 1; } method payCodeDelete {Src} { ::if {[payCodeExists $Src]} {::unset _payCodesArray($Src);} ::return $this; } method employeeAccountsMark {args} { ::array set Args $args; ::foreach AccountItem $Args(.accounts) { ::array set ItemArray $AccountItem; ::set Src $ItemArray(.address); ::set Import_Datum [[$Src ".import_datum"] odb_get]; ::sargs::var::set Import_Datum ".payroll_class" "PAYROLL/$ItemArray(.type)"; [$Src ".import_datum"] odb_set $Import_Datum; } ::foreach AccountItem $Args(.other_accounts) { ::array set ItemArray $AccountItem; ::set Src $ItemArray(.address); ::set Import_Datum [[$Src ".import_datum"] odb_get]; ::sargs::var::set Import_Datum ".payroll_class" "PAYROLL/$ItemArray(.type)"; [$Src ".import_datum"] odb_set $Import_Datum; } } method validate {Name Value} { ::set Value [::string trim $Value]; ::switch -- $Name { ".province_of_employment" { ::set Value [::string toupper $Value]; ::if {$Value ne ""&&[::lsearch -exact {AB BC MB NB NL NU NT NS ON PE PQ SK YK ZZ} $Value]==-1} { ::return ""; } } ".sex" { ::set Value [::string toupper $Value]; ::if {$Value ne "M"&&$Value ne "F"&&$Value ne ""} { ::return ""; } } ".state_jurisdiction" { ::set Value [::string toupper $Value]; ::if {$Value ne ""&&[::lsearch -exact [[$_manager "/OBJECT/NEWVIEWS/PAYROLL/USA"] state_tax_table_list] $Value]==-1} { ::return ""; } } "date" { ::set Year [::string range $Value 0 3]; ::set Year [::string trimleft $Year 0]; ::if {$Year eq ""} {::return "";} ::if {![string is integer $Year]} {::return "";} ::if {$Year<1903} {::return "19030101";} ::if {$Year>2037} {::return "20371231";} } default { import_error "Payroll validate did not recognize $Name."; } } ::return $Value; } method makeEmployeeIdUnique {Src} { ::regsub -all {[^0-9A-Z]} [::string toupper $Src] "" Src; ::set Suffix ""; ::while {[::info exists _employee_id_array($Src$Suffix)]} { ::if {$Suffix eq ""} {::set Suffix 1;} ::incr Suffix; } ::set Src $Src$Suffix; ::set _employee_id_array($Src) 1; ::return $Src; } method employeeCreate {args} { ::array set Args $args; ::set EmployeeName $Args(.prefix); ::if {$Args(.regAccount) eq ""} { import_error "No regular earnings account found for employee $EmployeeName."; } ::set EmployeeId [makeEmployeeIdUnique $Args(.prefix)]; ::if {$EmployeeId ne $Args(.prefix)} { ::append _payroll_convert_notes "* $Args(.prefix) - Id changed to $EmployeeId\n"; } else { ::append _payroll_convert_notes " $EmployeeId\n"; } status "Employee: $Args(.name)"; ::set Employee [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/EMPLOYEE/$_payrollCountry$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Employee ".folder"] odb_set "file"; [$Employee ".employee_id"] odb_set $EmployeeId; ::set Payroll [$_manager [::lindex $_payroll_list $Args(.payroll)]]; [$Employee ".payroll"] odb_set [$Payroll ".employees"]; ::set IsQuebecEmployee 0; ::if {$_payrollCountry eq "CANADA"} { [$Employee ".province_of_employment"] odb_set $_payrunFieldsArray(.province_of_employment); ::set IsQuebecEmployee $Args(.quebec); } else { [$Employee ".state/1.jurisdiction"] odb_set $_payrunFieldsArray(.state_jurisdiction); } ::set RegAccountName ""; ::array set Fields $Args(.records_fields); ::foreach Field {".date_of_birth" ".first_day_worked" ".last_day_worked"} { ::if {[::info exists Fields($Field)]} { ::if {[::string trim $Fields($Field)] eq ""} {::unset Fields($Field);::continue;} ::if {![::string is integer $Fields($Field)]} {::unset Fields($Field);::continue;} ::set Date [pgq_date_fix [nv1_keystroke_to_ymdhms $Fields($Field)]]; ::if {$Date ne ""} { ::set Date [validate "date" $Date]; ::set Fields($Field) $Date; } else { ::unset Fields($Field); } } } ::if {$_payrollCountry eq "CANADA" && [::info exists Fields(.social_insurance_number)]} { ::if {![[$Employee ".social_insurance_number"] isValid $Fields(.social_insurance_number)]} { ::set Fields(.social_insurance_number) ""; } } ::if {$_payrollCountry eq "USA" && [::info exists Fields(.social_security_number)]} { ::if {![[$Employee ".social_security_number"] isValid $Fields(.social_security_number)]} { ::set Fields(.social_security_number) ""; } } ::if {[::info exists Fields(.sex)]} { ::set Fields(.sex) [validate ".sex" $Fields(.sex)]; } ::foreach Field [::array names Fields] { ::if {$Fields($Field) ne ""} { ::if {$Field eq ".termination_code"} { [$Employee $Field] odb_set "K00"; #// Other ::continue; } [$Employee $Field] odb_set $Fields($Field); } } $Employee odb_commit; ::foreach AccountItem $Args(.accounts) { ::unset -nocomplain ItemArray; ::array set ItemArray $AccountItem; ::set Src $ItemArray(.address); ::set AccountName [[$Src ".name"] odb_get]; ::set ImportDatum [[$Src ".import_datum"] qw_get]; ::sargs::var::set Import_Datum ".payroll_class" "PAYROLL/$ItemArray(.type)"; ::set _account_class_array($AccountName-payroll_class) "PAYROLL/$ItemArray(.type)"; ::if {$AccountName eq $Args(.regAccount)} { ::sargs::var::set ImportDatum ".regular_earnings_account" 1; } ::if {$ItemArray(.isTotalAccount) && $ItemArray(.type) eq "NET"} { ::sargs::var::set ImportDatum ".employee_name" $Args(.name); } [$Src ".import_datum"] odb_set $ImportDatum; ::set Dest $Src; [$Dest ".employee"] odb_set [$Employee ".accounts"]; commit $Dest; ::if {$ItemArray(.isTotalAccount)} { ::continue; } ::array unset _payCodesArray; setPayCodes $ItemArray(.description); ::switch -- $_payrollCountry { "CANADA" { ::if {[payCodeValue "D"] eq "QTX"} { payCodeValue "D" "QTAX"; ::if {[payCodeExists "C"]} { payCodeValue "V" [payCodeValue "C"];payCodeDelete "C"; } ::if {[payCodeExists "V"]} { ::if {[::string is double [payCodeValue "V"]]} { [$Employee ".quebec.claim_amount"] odb_set [payCodeValueInteger "V"]; } else { ::if {[payCodeValue "V"] eq "X"} { [$Employee ".quebec.tax_exempt"] odb_set "yes"; } } payCodeDelete "V"; } ::if {[payCodeExists "R"]} {[$Employee ".quebec.additional_tax"] odb_set [payCodeValueInteger "R"];payCodeDelete "R";} ::if {[payCodeExists "E"]} {[$Employee ".quebec.additional_deduction"] odb_set [payCodeValueInteger "E"];payCodeDelete "E";} ::if {[payCodeExists "%"]} {[$Employee ".provincial.lsf_purchase_amount"] odb_set [payCodeValueInteger "%"];payCodeDelete "%";} } ::if {[payCodeExists "C"]} { ::if {[::string is double [payCodeValue "C"]]} { [$Employee ".federal.td1_claim_amount"] odb_set [payCodeValueInteger "C"]; } else { ::switch -- [payCodeValue "C"] { "X" { [$Employee ".federal.manual_tax_calculation"] odb_set "yes"; [$Employee ".provincial.manual_tax_calculation"] odb_set "yes"; } "E" { [$Employee ".federal.tax_exempt"] odb_set "yes"; [$Employee ".provincial.tax_exempt"] odb_set "yes"; } } } payCodeDelete "C"; } ::if {[payCodeExists "V"]} { ::if {[::string is double [payCodeValue "V"]]} { ::if {$IsQuebecEmployee} { [$Employee ".quebec.claim_amount"] odb_set [payCodeValueInteger "V"]; } else { [$Employee ".provincial.td1_claim_amount"] odb_set [payCodeValueInteger "V"]; } } else { ::if {$IsQuebecEmployee} { ::switch -- [payCodeValue "V"] { "X" {[$Employee ".qubec.tax_exempt"] odb_set "yes";} "Z" {[$Employee ".quebec.manual_tax_calculation"] odb_set "yes";} } } else { ::switch -- [payCodeValue "V"] { "X" {[$Employee ".provincial.manual_tax_calculation"] odb_set "yes";} "E" {[$Employee ".provincial.tax_exempt"] odb_set "yes";} } } } payCodeDelete "V"; } ::if {[payCodeExists "J"]} { ::set Province [payCodeValue "J"]; ::if {$Province eq "NN"} {::set Province "NU";} ::if {$Province eq "NF"} {::set Province "NL";} ::if {$Province eq "QT"} {::set Province "PQ";} ::set Province [validate ".province_of_employment" $Province]; ::if {$Province ne ""} { [$Employee ".province_of_employment"] odb_set $Province; } payCodeDelete "J"; } ::if {[payCodeValue "D"] eq "TAX"} { ::if {[payCodeExists "X"]} { [$Employee ".federal.additional_exemption"] odb_set [payCodeValueInteger "X"]; payCodeDelete "X"; } ::if {[payCodeExists "R"]} { [$Employee ".federal.td1_additional_tax"] odb_set [payCodeValueNumber "R"]; payCodeDelete "R"; } ::if {[payCodeExists "%"]} { [$Employee ".federal.lsf_purchase_amount"] odb_set [payCodeValueInteger "%"]; [$Employee ".provincial.lsf_purchase_amount"] odb_set [payCodeValueInteger "%"]; payCodeDelete "%"; } ::if {[payCodeExists "E"]} { ::if {[::string is double [payCodeValue "E"]]} { ::if {[payCodeValue "E"]<100} { [$Employee ".provincial.td1_y_factor"] odb_set [::expr [payCodeValue "E"]*334]; } else { [$Employee ".provincial.td1_y_factor"] odb_set [payCodeValue "E"]; } } } payCodeDelete "E"; } ::if {[payCodeValue "D"] eq "UIC"} {payCodeValue "D" "EI";} ::if {[payCodeValue "D"] eq "EI" && [payCodeValue "E"] eq "Y"} { [$Employee ".federal.ei_exempt"] odb_set "yes"; payCodeDelete "E"; } ::if {[payCodeValue "D"] eq "CPP"&&[payCodeValue "E"] eq "Y"} {[$Employee ".federal.cpp_exempt"] odb_set "yes";payCodeDelete "E";} ::if {[payCodeValue "D"] eq "QPP"&&[payCodeValue "E"] eq "Y"} {[$Employee ".federal.cpp_exempt"] odb_set "yes";payCodeDelete "E";} ::if {[$Dest normal_balance_get] eq "debit"} { ::set CodeList { "M" "description" "T" "quantity" "R" "rate" "%" "percent" "E" "exempt" "H" "insurable_hours" "B" "benefit_code" "I" "instruction_code" } } else { ::set CodeList { "M" "description" "D" "dos_type" "T" "quantity" "R" "rate" "%" "percent" "E" "exempt" "B" "benefit_code" "I" "instruction_code" } } } "USA" { ::if {[payCodeExists "J"]} { ::if {[payCodeExists "M"]} { ::switch -- [payCodeValue "M"] { "S" {[$Employee ".federal.marital_status"] odb_set "single";} "O" {[$Employee ".federal.marital_status"] odb_set "single";} "M" {[$Employee ".federal.marital_status"] odb_set "married";} "B" {[$Employee ".federal.marital_status"] odb_set "married";} "U" {[$Employee ".federal.marital_status"] odb_set "married";} "H" {[$Employee ".federal.marital_status"] odb_set "married";} "D" {[$Employee ".federal.marital_status"] odb_set "married";} "J" {[$Employee ".federal.marital_status"] odb_set "married";} "W" {[$Employee ".federal.marital_status"] odb_set "married";} "N" {[$Employee ".federal.marital_status"] odb_set "married";} default {[$Employee ".federal.marital_status"] odb_set "single";} } [$Employee ".state/1.marital_status"] odb_set [translate_state_marital_status [[$Employee ".state/1.jurisdiction"] odb_get] [payCodeValue "M"]]; payCodeDelete "M"; } ::if {[payCodeExists "D"]&&[payCodeValue "D"] eq "CIT"} { ::qw::try { [$Employee ".local/1.jurisdiction"] odb_set [payCodeValue "J"]; } catch Exception { ::puts "Could not set employee local jurisdiction to [payCodeValue J]. $Exception"; } } else { ::qw::try { [$Employee ".state/1.jurisdiction"] odb_set [payCodeValue "J"]; } catch Exception { ::puts "Could not set employee state jurisdiction to [payCodeValue J]. $Exception"; } } payCodeDelete "J"; } ::if {[payCodeExists "D"]} { ::switch -- [payCodeValue "D"] { "FIT" { ::if {[payCodeExists "M"]} { ::switch -- [payCodeValue "M"] { "M" {[$Employee ".federal.marital_status"] odb_set "married";} "S" {[$Employee ".federal.marital_status"] odb_set "single";} "B" {[$Employee ".federal.marital_status"] odb_set "married";} "O" {[$Employee ".federal.marital_status"] odb_set "single";} "U" {[$Employee ".federal.marital_status"] odb_set "married";} "H" {[$Employee ".federal.marital_status"] odb_set "married";} "D" {[$Employee ".federal.marital_status"] odb_set "married";} "J" {[$Employee ".federal.marital_status"] odb_set "married";} "W" {[$Employee ".federal.marital_status"] odb_set "married";} "N" {[$Employee ".federal.marital_status"] odb_set "married";} default {[$Employee ".federal.marital_status"] odb_set "single";} } payCodeDelete "M"; } ::if {[payCodeExists "X"]} {[$Employee ".federal.exemptions"] odb_set [payCodeValueInteger "X"];payCodeDelete "X";} ::if {[payCodeExists "R"]} {[$Employee ".federal.additional_tax"] odb_set [payCodeValueNumber "R"];payCodeDelete "R";} } "SIT" { ::if {[payCodeExists "R"]} {[$Employee ".state/1.additional_tax"] odb_set [payCodeValue "R"];payCodeDelete "R";} ::if {[payCodeExists "M"]} { [$Employee ".state/1.marital_status"] odb_set [translate_state_marital_status [[$Employee ".state/1.jurisdiction"] odb_get] [payCodeValue "M"]]; payCodeDelete "M"; } ::if {[[$Employee ".state/1.jurisdiction"] odb_get] eq "CA" || [[$Employee ".state/1.jurisdiction"] odb_get] eq "LA"} { ::if {[payCodeExists "X"] && [payCodeExists "B"]} { ::set Exemption [payCodeValue "X"]; ::set Benefit [payCodeValue "B"]; ::set Exemptions "$Exemption,$Benefit"; [$Employee ".state/1.exemptions"] odb_set $Exemptions; payCodeDelete "X"; payCodeDelete "B"; } } else { ::if {[payCodeExists "X"]} {[$Employee ".state/1.exemptions"] odb_set [payCodeValue "X"];payCodeDelete "X";} } ::if {[payCodeExists "L"]} { ::if {[[$Employee ".state/1.jurisdiction"] odb_get] eq "PR"} { ::switch -- [payCodeValue "L"] { "R" {[$Employee ".state/1.residence"] odb_set "resident";} "N" {[$Employee ".state/1.residence"] odb_set "non-resident-US-citizen";} "A" {[$Employee ".state/1.residence"] odb_set "non-resident-US-alien";} default {[$Employee ".state/1.residence"] odb_set "resident";} } } else { ::if {[[$Employee ".state/1.jurisdiction"] odb_get] eq "MD"} { ::switch -- [payCodeValue "L"] { "R" {[$Employee ".state/1.residence"] odb_set "resident";} "N" {[$Employee ".state/1.residence"] odb_set "non-resident";} "D" {[$Employee ".state/1.residence"] odb_set "maryland-residents-employed-in-delaware";} default {[$Employee ".state/1.residence"] odb_set "resident";} } } else { ::switch -- [payCodeValue "L"] { "R" {[$Employee ".state/1.residence"] odb_set "resident";} "N" {[$Employee ".state/1.residence"] odb_set "non-resident";} default {[$Employee ".state/1.residence"] odb_set "resident";} } payCodeDelete "L"; } } } } "CIT" { ::if {[payCodeExists "M"]} { ::switch -- [payCodeValue "M"] { "M" {[$Employee ".local/1.marital_status"] odb_set "married";} "S" {[$Employee ".local/1.marital_status"] odb_set "single";} default {[$Employee ".local/1.marital_status"] odb_set "single";} } payCodeDelete "M"; } ::if {[payCodeExists "X"]} {[$Employee ".local/1.exemptions"] odb_set [payCodeValue "X"];payCodeDelete "X";} ::if {[payCodeExists "L"]} { ::switch -- [payCodeValue "L"] { "R" {[$Employee ".local/1.residence"] odb_set "resident";} "N" {[$Employee ".local/1.residence"] odb_set "non-resident";} default {[$Employee ".local/1.residence"] odb_set "resident";} } payCodeDelete "L"; } ::if {[payCodeExists "R"]} {[$Employee ".local/1.additional_tax"] odb_set [payCodeValue "R"];payCodeDelete "R";} } } } ::if {[$Dest normal_balance_get] eq "debit"} { ::set CodeList { "S" "description" "T" "quantity" "R" "rate" "%" "percent" "E" "exempt" "I" "instruction_code" "B" "benefit" } } else { ::set CodeList { "S" "description" "D" "dos_type" "T" "quantity" "R" "rate" "%" "percent" "E" "exempt" "I" "instruction_code" } } } } $Employee odb_commit; ::if {[payCodeExists "A"]&&[payCodeValue "A"] ne "Y"} {payCodeValue "A" "Y";} ::if {[payCodeValue "I"] eq "Z"} {payCodeDelete "Z";} ::if {[payCodeExists "P"]} {payCodeDelete "P";} ::set Paycodes [[$Dest ".paycodes"] odb_get]; ::set NormalBalance [$Dest normal_balance_get]; ::set Settings [::sargs::get $Paycodes "/$NormalBalance"]; ::if {[payCodeExists "A"]} { ::switch -- $NormalBalance { "debit" { ::sargs::var::set Settings ".type" "Advance"; ::if {[payCodeExists "R"]} {::sargs::var::set Settings ".rate" [payCodeValueNumber "R"];} ::if {[payCodeExists "%"]} {::sargs::var::set Settings ".percent" [payCodeValueNumber "%"];} } "credit" { ::sargs::var::set Settings ".type" "Reimbursement"; ::if {[payCodeExists "R"]} {::sargs::var::set Settings ".rate" [payCodeValueNumber "R"];} ::if {[payCodeExists "%"]} {::sargs::var::set Settings ".percent" [payCodeValueNumber "%"];} } } } else { ::foreach {Code1 Code2} $CodeList { ::if {![payCodeExists $Code1]} {::continue;} ::switch -- $Code1 { "R" - "%" - "T" { ::if {([::string tolower [::string index [payCodeValue $Code1] 0]] eq "i" \ ||[::string tolower [::string index [payCodeValue $Code1] 0]] eq "a") \ && $Code1 ne "%" \ } { ::sargs::var::set Settings ".$Code2" "input"; } else { ::sargs::var::set Settings ".$Code2" [payCodeValueNumber $Code1]; } } default { ::sargs::var::set Settings ".$Code2" [payCodeValue $Code1]; } } } } ::set Percent [::sargs::get $Settings ".percent"]; ::if {$Percent eq ""||![::string is double $Percent]} { ::sargs::var::set Settings ".percent" ""; ::set Percent 0; } ::set Rate [::sargs::get $Settings ".rate"]; ::if {$Rate eq ""||![::string is double $Rate]} { ::sargs::var::set Settings ".rate" ""; ::set Rate 0; } ::if {$Percent!=0.0} { ::if {$Rate!=0.0} { ::sargs::var::set Settings ".annual_limit" [::format %.2f [::qw::number::round2 [::expr $Rate*$Percent*.01]]]; ::sargs::var::set Settings ".rate" ""; } } ::sargs::var::set Paycodes "/$NormalBalance" $Settings; [$Dest ".paycodes"] odb_set $Paycodes; [$Dest ".description"] odb_set [makeTextDescription \ -codes [::array get _payCodesArray] \ -normal_balance [$Dest normal_balance_get] \ -suffix [::lindex [splitAccountName $AccountName] 2] \ -quebec $IsQuebecEmployee \ -country $_payrollCountry \ ] commit $Dest; } ::set Import_Datum [[$Employee ".import_datum"] odb_get]; ::foreach AccountItem $Args(.other_accounts) { ::array set ItemArray $AccountItem; ::sargs::var::set Import_Datum ".gt_accounts/$ItemArray(.type)" $ItemArray(.name); } ::sargs::var::set Import_Datum ".reg_account" $Args(.regAccount); ::if {$_payrollCountry eq "CANADA"} { ::set Benefits_Info [find_benefits_accounts $Args(.accounts)]; ::sargs::var::set Import_Datum ".benefits" $Benefits_Info; ::foreach Sub [::sargs::subs .structure $Benefits_Info] { ::set Benefit_Info [::sargs::get $Benefits_Info $Sub]; ::set Benefit [::sargs::get $Benefit_Info ".benefit"]; ::foreach Field [::sargs::names .structure $Benefit_Info] { ::set Value [::sargs::get $Benefit_Info "$Field"]; ::switch -- $Field { ".benefit" - ".account" {::continue;} ".taxable" - ".pensionable" - ".insurable" - ".ppip_insurable" { ::if {$Value} { ::set Value "yes" } else { ::set Value "no" } } } [$Employee ".non_cash_taxable_benefits/$Benefit$Field"] odb_set $Value; } [$Employee ".non_cash_taxable_benefits/$Benefit.amount_period"] odb_set "pay-period"; ::foreach Sign {debit credit} { ::set AccountName [::sargs::get $Benefit_Info ".account/$Sign"]; ::set Account [account_get $AccountName]; ::set Account_Import_Datum [[$Account ".import_datum"] qw_get]; ::sargs::var::set Account_Import_Datum ".history_ignore" 1; [$Account ".import_datum"] odb_set $Account_Import_Datum; } } } [$Employee ".import_datum"] odb_set $Import_Datum; commit $Employee; ::foreach TextLine $Args(.text_lines) { $TextLine odb_destroy; } ::set CppSeen 0; ::set EiSeen 0; ::set TaxSeen 0; ::set QtxSeen 0; ::set PpipSeen 0; ::set FicaSeen 0; ::set MediSeen 0; ::set FitSeen 0; ::set SitSeen 0; ::set CitSeen 0; ::foreach AccountItem $Args(.accounts) { ::unset -nocomplain ItemArray; ::array set ItemArray $AccountItem; ::if {$ItemArray(.isTotalAccount)} {::continue;} ::set Account $ItemArray(.address); ::unset -nocomplain _payCodesArray; ::unset -nocomplain NewCodes; ::set Paycodes [[$Account ".paycodes"] odb_get]; ::set NormalBalance [$Account normal_balance_get]; ::array set _payCodesArray [::sargs::get $Paycodes "/$NormalBalance"]; ::switch -- $_payrollCountry { "CANADA" { ::array set NewCodes { .description "" .type "" .quantity "" .rate "" .percent "" .percentage_base "" .frequency "pay-period" .annual_limit "" .t4 "" .t4a "" .releve1 "" .tax "" .cpp "" .ppip "" .ei "" .quebec_tax "" .vacation_pay "" .tag "" } ::if {[$Account normal_balance_get] eq "debit"} { ::array set NewCodes { .insurable_hours "" .roe_period "" } } ::if {[payCodeExists ".description"]} {::array set NewCodes [::list .description [payCodeValue ".description"]];} ::if {[payCodeExists ".percent"]} { ::set NewCodes(.percent) [payCodeValueNumber ".percent"]; ::if {[payCodeExists ".instruction_code"]} { ::if {[payCodeValue ".instruction_code"] eq "N"} { ::set NewCodes(.percentage_base) "NET"; } } } ::if {[payCodeExists ".rate"]} {::array set NewCodes [::list .rate [payCodeValueNumber ".rate"]];} ::if {[payCodeExists ".quantity"]} {::array set NewCodes [::list .quantity [payCodeValue ".quantity"]];} ::if {[payCodeExists ".annual_limit"]} {::array set NewCodes [::list .annual_limit [payCodeValueNumber ".annual_limit"]];} ::if {[payCodeValue ".type"] eq "Advance"||[payCodeValue ".type"] eq "Reimbursement"} { ::set NewCodes(.type) [payCodeValue ".type"]; ::if {[payCodeExists ".rate"]} {::set NewCodes(.rate) [payCodeValue ".rate"]}; ::if {[payCodeExists ".percent"]} {::set NewCodes(.percent) [payCodeValue ".percent"]}; ::array set NewCodes {.t4 "" .t4a "" .releve1 "" .tax "no" .cpp "no" .ei "no" .ppip "no" .quebec_tax "no" .vacation_pay "no"}; ::sargs::var::set Paycodes "/$NormalBalance" [::array get NewCodes]; [$Account ".paycodes"] odb_set $Paycodes; commit $Account; ::continue; } ::if {[$Account normal_balance_get] eq "debit"} { ::array set NewCodes {.tax "yes" .cpp "yes" .ei "yes" .ppip "yes" .quebec_tax "yes" .vacation_pay "yes" .roe_period "Earned"}; ::array set NewCodes {.type "REGULAR" .t4 "14" .releve1 "A"}; ::switch -- [payCodeValue ".exempt"] { "Y" {::array set NewCodes {.tax "no" .cpp "no" .ei "no" .ppip "no" .quebec_tax "no" .vacation_pay "no" .t4 "" .releve1 ""};} "AV" - "YV" {::array set NewCodes {.tax "no" .cpp "no" .ei "no" .ppip "no" .quebec_tax "no" .vacation_pay "no" .t4 "" .releve1 "" .type "VACATIONEARNED"};} "U" {::array set NewCodes {.tax "yes" .cpp "yes" .ei "no" .ppip "no" .quebec_tax "yes" .vacation_pay "yes"};} "B" {::array set NewCodes {.vacation_pay "no" .type "BONUS"};} "V" { ::array set NewCodes {.vacation_pay "no" .type "VACATIONPAID" .roe_period "paid"}; ::if {[[$Employee ".province_of_employment"] odb_get] eq "AB"} {::array set NewCodes {.vacation_pay "yes"};} } "C" {::array set NewCodes {.tax "no" .cpp "no" .ei "yes" .ppip "yes" .quebec_tax "no" .vacation_pay "yes"};} "CB" {::array set NewCodes {.vacation_pay "no" .t4 "42" .releve1 "M" .type "BONUS"};} "CM" {::array set NewCodes {.vacation_pay "no" .t4 "42" .releve1 "M"};} "Q" {::array set NewCodes {.tax "no" .ei "no" .ppip "no" .quebec_tax "yes" .vacation_pay "yes"};} } ::switch -- [payCodeValue ".insurable_hours"] { "time" - "input" - "calculate" {::set NewCodes(.insurable_hours) [payCodeValue ".insurable_hours"];} default { ::if {[payCodeValue ".insurable_hours"] ne "" && [::string is double [payCodeValue ".insurable_hours"]]} { ::set NewCodes(.insurable_hours) [payCodeValue ".insurable_hours"]; } } } ::if {[payCodeExists ".benefit_code"]} { ::set BCode [payCodeValue ".benefit_code"]; ::if {[::string range $BCode 0 1] eq "T4"} { ::array set NewCodes {.ei "no"}; ::switch -- [::string range $BCode 2 end] { "30" {::array set NewCodes {.t4 "30" .releve1 "H" .ei "yes"}} "31" {::array set NewCodes {.t4 "31" .releve1 ""}} "32" {::array set NewCodes {.t4 "32" .releve1 "K"}} "33" {::array set NewCodes {.t4 "33" .releve1 ""}} "34" {::array set NewCodes {.t4 "34" .releve1 "I"}} "35" {::array set NewCodes {.t4 "35" .releve1 ""}} "36" {::array set NewCodes {.t4 "36" .releve1 "L"}} "37" {::array set NewCodes {.t4 "37" .releve1 ""}} "38" {::array set NewCodes {.t4 "38" .releve1 "L"}} "39" {::array set NewCodes {.t4 "39" .releve1 ""}} "40" {::array set NewCodes {.t4 "40" .releve1 "L"}} "41" {::array set NewCodes {.t4 "41" .releve1 ""}} "42" {::array set NewCodes {.t4 "42" .releve1 "M"}} "70" {::array set NewCodes {.t4 "70" .releve1 ""}} "71" {::array set NewCodes {.t4 "71" .releve1 "R"}} "72" {::array set NewCodes {.t4 "72" .releve1 ""}} "73" {::array set NewCodes {.t4 "73" .releve1 ""}} "74" {::array set NewCodes {.t4 "74" .releve1 ""}} "75" {::array set NewCodes {.t4 "75" .releve1 ""}} "76" {::array set NewCodes {.t4 "76" .releve1 ""}} "H" {::array set NewCodes {.t4 "30" .releve1 "H"}} "I" {::array set NewCodes {.t4 "34" .releve1 "I"}} "J" {::array set NewCodes {.t4 "" .releve1 "J"}} "K" {::array set NewCodes {.t4 "32" .releve1 "K"}} "L" {::array set NewCodes {.t4 "40" .releve1 "L"}} "M" {::array set NewCodes {.t4 "42" .releve1 "M"}} "N" {::array set NewCodes {.t4 "46" .releve1 "N"}} "O" {::array set NewCodes {.t4 "" .releve1 "O"}} "P" {::array set NewCodes {.t4 "" .releve1 "P"}} "Q" {::array set NewCodes {.t4 "" .releve1 "Q"}} "R" {::array set NewCodes {.t4 "71" .releve1 "R"}} "S" {::array set NewCodes {.t4 "" .releve1 "S"}} "T" {::array set NewCodes {.t4 "14" .releve1 "T"}} "U" {::array set NewCodes {.t4 "14" .releve1 "U"}} } } } } else { ::array set NewCodes {.t4 "" .t4a "" .releve1 "" .tax "no" .cpp "no" .ei "no" .ppip "no" .quebec_tax "no" .vacation_pay "no"}; ::array set NewCodes {.type "OTHER"}; ::switch -- [payCodeValue ".exempt"] { "R" {::array set NewCodes {.tax "yes" .cpp "no" .ei "no" .quebec_tax "yes" .vacation_pay "no" .t4 "" .releve1 ""};} "AV" - "YV" {::array set NewCodes {.tax "no" .cpp "no" .ei "no" .quebec_tax "no" .vacation_pay "no" .t4 "" .releve1 "" .type "VACATIONACCRUED"};} } ::switch -- [payCodeValue ".dos_type"] { "CPP" {::array set NewCodes {.t4 "16" .releve1 "B" .type "CPP"};::set CppSeen 1;} "EI" {::array set NewCodes {.t4 "18" .releve1 "C" .type "EI"};::set EiSeen 1;} "TAX" {::array set NewCodes {.t4 "22" .t4a "022" .releve1 "" .type "TAX"};::set TaxSeen 1;} "QTAX" {::array set NewCodes {.t4 "" .releve1 "E" .type "QTAX"};::set QtxSeen 1;} "QPP" {::array set NewCodes {.t4 "17" .releve1 "B" .type "QPP"};::set CppSeen 1;} "UNION" {::array set NewCodes {.t4 "44" .releve1 "F" .type "UNION" .tax "yes" .quebec_tax "yes"}} "DON" {::array set NewCodes {.t4 "46" .t4a "046" .releve1 "N" .type "DONATION"}} "RPP" {::array set NewCodes {.t4 "20" .releve1 "" .tax "yes" .quebec_tax "yes" .type "RPP"}} "RRSP" {::array set NewCodes {.t4 "" .releve1 "" .tax "yes" .quebec_tax "yes" .type "RRSP"}} "PPIP" {::array set NewCodes {.t4 "55" .releve1 "" .type "PPIP"};::set PpipSeen 1;} } ::if {[payCodeExists "benefit_code"]} { ::array set NewCodes {.type "BENEFIT"}; } } ::if {[$Account normal_balance_get] eq "debit"&&[payCodeValue ".exempt"] ne "Y"&&[::lsearch -exact "CPP EI TAX QTAX QPP PPIP" [payCodeValue ".dos_type"]]<0} { ::if {$CppSeen} {::set NewCodes(.cpp) "yes";} ::if {$EiSeen} {::set NewCodes(.ei) "yes";} ::if {$TaxSeen} {::set NewCodes(.tax) "yes";} ::if {$QtxSeen} {::set NewCodes(.quebec_tax) "yes";} ::if {$PpipSeen} {::set NewCodes(.ppip) "yes";} } } "USA" { ::array set NewCodes { .description "" .type "" .quantity "" .rate "" .percent "" .percentage_base "" .annual_limit "" .frequency "pay-period" .w2 "" .1099 "" .federal_tax "" .state_tax1 "" .state_tax2 "" .local_tax1 "" .local_tax2 "" .social_security "" .medicare "" .futa "" .unemployment_insurance "" .sdi "" .vacation_pay "" .tag "" } ::if {[payCodeExists ".description"]} {::array set NewCodes [::list .description [payCodeValue ".description"]];} ::if {[payCodeExists ".percent"]} { ::set NewCodes(.percent) [payCodeValueNumber ".percent"]; ::if {[payCodeExists ".instruction_code"]} { ::if {[payCodeValue ".instruction_code"] eq "N"} { ::set NewCodes(.percentage_base) "NET"; } } } ::if {[payCodeExists ".rate"]} {::array set NewCodes [::list .rate [payCodeValueNumber ".rate"]];} ::if {[payCodeExists ".quantity"]} {::array set NewCodes [::list .quantity [payCodeValue ".quantity"]];} ::if {[payCodeExists ".annual_limit"]} {::array set NewCodes [::list .annual_limit [payCodeValueNumber ".annual_limit"]];} ::if {[payCodeValue ".type"] eq "Advance"||[payCodeValue ".type"] eq "Reimbursement"} { ::set NewCodes(.type) [payCodeValue ".type"]; ::if {[payCodeExists ".rate"]} {::set NewCodes(.rate) [payCodeValue ".rate"]}; ::if {[payCodeExists ".percent"]} {::set NewCodes(.percent) [payCodeValue ".percent"]}; ::array set NewCodes {.federal_tax "no" .state_tax1 "no" .state_tax2 "no" .local_tax1 "no" .local_tax2 "no" .social_security "no" .medicare "no" .futa "no" .unemployment_insurance "no" .sdi "no" .w2 "" .1099 "" .vacation_pay "no"}; ::sargs::var::set Paycodes "/$NormalBalance" [::array get NewCodes]; [$Account ".paycodes"] odb_set $Paycodes; commit $Account; ::continue; } ::if {[$Account normal_balance_get] eq "debit"} { ::array set NewCodes {.federal_tax "yes" .state_tax1 "yes" .state_tax2 "yes" .local_tax1 "yes" .local_tax2 "yes" .social_security "yes" .medicare "yes" .futa "yes" .unemployment_insurance "yes" .sdi "yes" .vacation_pay "yes"}; ::array set NewCodes {.type "REGULAR" .w2 "1" .1099 ""}; ::switch -- [payCodeValue ".exempt"] { "Y" {::array set NewCodes {.federal_tax "no" .state_tax1 "no" .state_tax2 "no" .local_tax1 "no" .local_tax2 "no" .social_security "no" .medicare "no" .futa "no" .unemployment_insurance "no" .sdi "no" .w2 "" .1099 "" .vacation_pay "no"};} "S" {::array set NewCodes {.type "SUPPLEMENTAL"};} "C" {::array set NewCodes {.federal_tax "no" .state_tax1 "no" .state_tax2 "no" .local_tax1 "no" .local_tax2 "no" .social_security "yes" .medicare "yes" .futa "no" .unemployment_insurance "no" .sdi "no" .vacation_pay "yes"};} "AV" - "YV" {::array set NewCodes {.federal_tax "no" .state_tax1 "no" .state_tax2 "no" .local_tax1 "no" .local_tax2 "no" .social_security "no" .medicare "no" .futa "no" .unemployment_insurance "no" .sdi "no" .type "VACATIONEARNED" .vacation_pay "no"};} "V" {::array set NewCodes {.type "VACATIONPAID" .vacation_pay "no"};} } ::switch -- [payCodeValue ".benefit"] { "EIC" { ::array set NewCodes {.w2 "9" .1099 "" .type "EIC" .federal_tax "no" .state_tax1 "no" .state_tax2 "no" .local_tax1 "no" .local_tax2 "no" .social_security "no" .medicare "no" .futa "no" .unemployment_insurance "no" .sdi "no" .vacation_pay "no"}; } } } else { ::array set NewCodes {.w2 "" .1099 "" .federal_tax "no" .state_tax1 "no" .state_tax2 "no" .local_tax1 "no" .local_tax2 "no" .social_security "no" .medicare "no" .futa "no" .unemployment_insurance "no" .sdi "no" .vacation_pay "no"}; ::array set NewCodes {.type "OTHER"}; ::switch -- [payCodeValue ".exempt"] { "R" {::array set NewCodes {.federal_tax "yes" .state_tax1 "yes" .state_tax2 "yes" .local_tax1 "yes" .local_tax2 "yes" .social_security "yes" .medicare "yes" .futa "yes" .unemployment_insurance "yes" .w2 "1" .1099 "" .vacation_pay "yes"};} "AV" - "YV" {::array set NewCodes {.type "VACATIONACCRUED"};} } ::set StateJurisdiction [[$Employee ".state/1.jurisdiction"] odb_get]; ::switch -- [payCodeValue ".dos_type"] { "FICA" {::array set NewCodes {.w2 "4" .1099 "" .type "FICA"};::set FicaSeen 1;} "MEDI" {::array set NewCodes {.w2 "6" .1099 "" .type "MEDI"};::set MediSeen 1;} "FIT" {::array set NewCodes {.w2 "2" .1099 "" .type "FIT"};::set FitSeen 1;} "SIT" {::array set NewCodes {.w2 "17" .1099 "" .type "SIT1"};::set SitSeen 1;} "CIT" { ::if {[payCodeExists "J"]} { ::switch -- [payCodeValue "J"] { "10" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} "20" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} "30" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} "40" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} "50" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} "60" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} "80" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} "85" {::array set NewCodes {.w2 "19" .1099 "" .type "SDI"};::set CitSeen 1;} "90" {::array set NewCodes {.w2 "19" .1099 "" .type "SDI"};::set CitSeen 1;} "99" {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} } } else {::array set NewCodes {.w2 "19" .1099 "" .type "CIT1"};::set CitSeen 1;} } "XCAF" { ::array set NewCodes {.w2 "" .1099 "" .federal_tax "no" .state_tax1 "no" .description "User defined deduction"}; } "401K" { ::array set NewCodes {.w2 "12D" .1099 "" .type "401K" .federal_tax "yes" .state_tax1 "yes" .description "401K Cafeteria Plan"} ::if {$StateJurisdiction eq "NJ"||$StateJurisdiction eq "PA"} { ::array set NewCodes {.state_tax1 "no"}; } } "403B" { ::array set NewCodes {.w2 "12E" .1099 "" .type "403B" .federal_tax "yes" .state_tax1 "yes" .description "403B Cafeteria Plan"} ::if {$StateJurisdiction eq "NJ"||$StateJurisdiction eq "PA"} { ::array set NewCodes {.state_tax1 "no"}; } } "S125" { ::array set NewCodes {.w2 "" .1099 "" .type "S125" .federal_tax "yes" .state_tax1 "yes" .social_security "yes" .medicare "yes" .description "S125 Cafeteria Plan"} ::if {$StateJurisdiction eq "NJ"||$StateJurisdiction eq "PR"||$StateJurisdiction eq "DC"} { ::array set NewCodes {.state_tax1 "no"}; } } "S125S" { ::array set NewCodes {.w2 "" .1099 "" .type "S125S" .federal_tax "yes" .state_tax1 "yes" .description "S125S Cafeteria Plan"} ::if {$StateJurisdiction eq "NJ"||$StateJurisdiction eq "PR"||$StateJurisdiction eq "DC"} { ::array set NewCodes {.state_tax1 "no"} } } } } ::if {[::lsearch -exact "FICA MEDI FIT SIT CIT" [payCodeValue ".dos_type"]]<0} { ::if {$FicaSeen} {::set NewCodes(.social_security) "yes";} ::if {$MediSeen} {::set NewCodes(.medicare) "yes";} ::if {$FitSeen} {::set NewCodes(.federal_tax) "yes";} ::if {$SitSeen} {::set NewCodes(.state_tax1) "yes";} ::if {$CitSeen} {::set NewCodes(.local_tax1) "yes";} } } } ::if {[::info exists NewCodes(.dos_type)]} { ::unset NewCodes(.dos_type); } ::set NewCodes(.type) [$Account type_name_to_description $NewCodes(.type)] ::sargs::var::set Paycodes "/$NormalBalance" [::array get NewCodes]; [$Account ".paycodes"] odb_set $Paycodes; commit $Account; } ::foreach AccountItem $Args(.other_accounts) { ::unset -nocomplain ItemArray; ::array set ItemArray $AccountItem; ::set Src $ItemArray(.address); ::set Import_Datum [[$Src ".import_datum"] qw_get]; ::sargs::var::set Import_Datum ".history_ignore" 1; ::sargs::var::set Import_Datum ".payroll_class" "PAYROLL/$ItemArray(.type)"; ::set _account_class_array($ItemArray(.name)-payroll_class) "PAYROLL/$ItemArray(.type)"; [$Src ".import_datum"] odb_set $Import_Datum; [$Src ".employee"] odb_set [$Employee ".accounts"]; commit $Src; } ::return $this; } public method translate_state_marital_status {State DOSCode} { ::if {$DOSCode eq ""} {::return "";} ::if {$State eq ""} {::return "";} ::switch $State { {AL} { ::switch -- $DOSCode { "S" {::return "single"} "H" {::return "head-of-household"} "C" {::return "zero"} "M" {::return "married"} default {::return "single"} } } {AR} { ::switch -- $DOSCode { "S" {::return "single"} "B" {::return "both"} "O" {::return "zero"} "M" {::return "married"} default {::return "single"} } } {AZ} {::return "not-applicable"} {CA} { ::switch -- $DOSCode { "S" {::return "single"} "H" {::return "head-of-household"} "U" {::return "head-of-household"} "M" {::return "married"} default {::return "single"} } } {CO} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {CT} { ::switch -- $DOSCode { "S" {::return "single"} "X" {::return "exempt"} "B" {::return "married-filing-jointly-both-spouses-workingceiling"} default {::return "single"} } } {DC} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married-filing-separately"} "J" {::return "married-filing-jointly"} default {::return "single"} } } {DE} { ::switch -- $DOSCode { "S" {::return "single-standard-deduction"} "J" {::return "married-both-filing-standard-deduction"} "M" {::return "married-standard-deduction"} default {::return "single"} } } {GA} { ::switch -- $DOSCode { "S" {::return "single"} "H" {::return "head-of-household"} "U" {::return "head-of-household"} "J" {::return "married-filing-jointly-one-spouse-working"} "B" {::return "married-filing-jointly-one-spouse-working"} "M" {::return "married-filing-separately"} "O" {::return "zero"} default {::return "single"} } } {HI} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {IA} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {ID} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {IL} {::return "not-applicable"} {IN} {::return "not-applicable"} {KS} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {KY} {::return "not-applicable"} {LA} {::return "not-applicable"} {MA} {::return "not-applicable"} {MD} {::return "not-applicable"} {ME} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} "J" {::return "married-filing-jointly"} "O" {::return "married-filing-jointly"} default {::return "single"} } } {MI} {::return "not-applicable"} {MN} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {MO} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married-one-spouse-working"} "H" {::return "head-of-household"} "B" {::return "married-both-spouses-working"} default {::return "single"} } } {MS} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} "H" {::return "head-of-household"} "B" {::return "married-both-spouses-working"} "J" {::return "married-one-spouse-working"} default {::return "single"} } } {MT} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {NC} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} "H" {::return "head-of-household"} "W" {::return "widow"} default {::return "single"} } } {ND} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {NE} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {NJ} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} "C" {::return "new-jersey-rate-c"} "D" {::return "new-jersey-rate-d"} "E" {::return "new-jersey-rate-e"} default {::return "single"} } } {NM} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {NY} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {OH} {::return "not-applicable"} {OK} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married-filing-separately"} "H" {::return "head-of-household"} "W" {::return "widow"} "B" {::return "married-both-spouses-working"} "J" {::return "married-filing-jointly"} default {::return "single"} } } {OR} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {PA} {::return "not-applicable"} {PR} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married-filing-jointly-claiming-all"} "O" {::return "married-filing-separately-claiming-all"} "J" {::return "married-filing-jointly-claiming-half"} default {::return "single"} } } {RI} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {SC} {::return "not-applicable"} {UT} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {VA} {::return "not-applicable"} {VT} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {WI} { ::switch -- $DOSCode { "S" {::return "single"} "M" {::return "married"} default {::return "single"} } } {WV} {::return "not-applicable"} default { ::qw::throw [::sargs \ .text "Unknown state \"$State\"." \ .help_id 271820050404144050 \ ]; } } } method check_payroll_accounts_class {args} { ::array set Args $args; ::set Accounts ""; ::foreach AccountItem $Args(.accounts) { ::lappend Accounts [::eval check_payroll_accounts_class_item $AccountItem]; } ::set Args(.accounts) $Accounts; ::set Accounts ""; ::foreach AccountItem $Args(.other_accounts) { ::lappend Accounts [::eval check_payroll_accounts_class_item $AccountItem]; } ::set Args(.other_accounts) $Accounts; ::return [::array get Args]; } method check_payroll_accounts_class_item {args} { ::array set ItemArray $args; ::set AccountPayrollObject [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/${_payrollCountry}"]; ::set Src $ItemArray(.address); ::if {$::qw::control(airtech)} { ::if {$Src eq ""} {::return $args;} } ::if {[[$Src ".total.kids"] odb_items]!=0} {::return $args;} ::if {[$Src odb_is_a $AccountPayrollObject]} {::return $args;} status "Converting account $ItemArray(.name) to a payroll account." ::set Dest [change_account_class $Src "PAYROLL/${_payrollCountry}" "PAYROLL"]; ::set ItemArray(.master) $Dest; ::set ItemArray(.address) [$Dest odb_address]; ::return [::array get ItemArray]; } method change_account_class {Src Class NplClass} { ::if {[[$Src ".report"] odb_get] eq ""} {::return "";} ::set Dest [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/$Class$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Dest ".folder"] odb_set "file"; [$Dest ".line_type"] odb_set "account"; [$Dest ".description"] odb_set [[$Src ".description"] qw_get]; [$Dest ".normal_balance"] odb_set [$Src normal_balance_get]; [$Dest ".setup_column"] odb_set [[$Src ".setup_column"] qw_get]; [$Dest ".underline"] odb_set [[$Src ".underline"] qw_get]; [$Dest ".report"] odb_set [[$Src ".report"] qw_get]; [$Dest ".notes"] odb_set [[$Src ".notes"] qw_get]; [$Dest ".records"] odb_set [[$Src ".records"] qw_get]; [$Dest ".import_datum"] odb_set [[$Src ".import_datum"] qw_get]; commit $Dest; [$Dest ".total.parent1"] odb_set [[$Src ".total.parent1"] qw_get]; [$Dest ".total.parent2"] odb_set [[$Src ".total.parent2"] qw_get]; [$Dest ".nplclass"] odb_set $NplClass; ::set Name [[$Src ".name"] odb_get]; commit $Dest; ::set Index [[[$Src ".report"] odb_get] ".index/interactive"]; $Index odb_make_before [$Dest ".report"] [$Src ".report"]; ::if {[[$Src ".total.kids"] odb_items]!=0} { ::set TotalKids [[$Src ".total.kids.index/name"] odb_masters]; ::foreach Master $TotalKids { ::set TotalTo [[$Master ".total.parent1"] odb_get]; ::if {$TotalTo ne ""} { ::set TotalToMaster [$TotalTo odb_master]; ::if {$TotalToMaster eq $Src} { [$Master ".total.parent1"] odb_set $Dest; commit $Master; } } ::set TotalTo [[$Master ".total.parent2"] odb_get]; ::if {$TotalTo ne ""} { ::set TotalToMaster [$TotalTo odb_master]; ::if {$TotalToMaster eq $Src} { [$Master ".total.parent2"] odb_set $Dest; commit $Master; } } } } $Src odb_destroy; [$Dest ".name"] odb_set $Name; commit $Dest; ::set _account_class_array($Name) $NplClass; ::return $Dest; } method makeTextDescription {args} { ::array set Args $args; ::array set Codes $Args(-codes); ::switch -- $Args(-country) { "CANADA" { ::if {[::info exists Codes(M)] && [::string index $Codes(M) 0] ne "@"} {::return $Codes(M);} } "USA" { ::if {[::info exists Codes(S)] && [::string index $Codes(S) 0] ne "@"} {::return $Codes(S);} } } ::if {$Args(-normal_balance) eq "debit"} { ::if {[::info exists Codes(E)]} { ::if {$Codes(E) eq "YV"||$Codes(E) eq "AV"} {::return "Vacation Pay Earned";} ::if {$Codes(E) eq "V"||$Codes(E) eq "AV"} {::return "Vacation Pay Paid";} } ::if {[::info exists Codes(A)]} {::return "Advance";} ::return "$Args(-suffix) earnings"; } else { ::if {[::info exists Codes(A)]} {::return "Reimbursement";} ::if {[::info exists Codes(D)]} { ::switch -- $Args(-country) { "CANADA" { ::switch -- $Codes(D) { "EI" {::return "Employment Insurance";} "CPP" {::return "Canada Pension Plan";} "QPP" {::return "Quebec Pension Plan";} "TAX" { ::if {$Args(-quebec)} {::return "Federal Income Tax";} ::return "Income Tax"; } "QTAX" {::return "Quebec Tax";} "RPP" {::return "Pension Plan";} "RRSP" {::return "R.R.S.P.";} "UNION" {::return "Union Dues";} "DON" {::return "Donation";} "PPIP" {::return "Provincial Parental Insurance Plan";} default {::return "$Codes(D) Deduction";} } } "USA" { ::switch -- $Codes(D) { "FICA" {::return "Social Security";} "MEDI" {::return "Medicare";} "FIT" {::return "Federal Income Tax";} "SIT" {::return "State Income Tax";} "UNION" {::return "Union Dues";} default {::return "$Codes(D) Deduction";} } } default {import_error "Cannot convert paycodes for country \"$Args(-country)\".";} } } ::if {[::info exists Codes(E)]} { ::if {$Codes(E) eq "YV"||$Codes(E) eq "AV"} { ::return "Vacation Pay Withheld"; } } ::return "$Args(-suffix) deduction"; } ::return $Args(-suffix); } method loadNplSetup {} { loadNplSetupP; loadNplSetupS; } method loadNplSetupP {} { ::set _purchase_tax_library ""; ::set _gst_rebate_percent "100"; ::if {[procedureExists "TAXP"]} { ::set ProcNotes [procedureNotes "TAXP"]; ::set Index [::string first "@rebate%=" [::string tolower $ProcNotes]]; ::if {$Index>=0} { ::incr Index 9; ::set String [::lindex [::string trim [::string range $ProcNotes $Index end]] 0]; ::if {$String ne ""&&[::string is double $String]} { ::set _gst_rebate_percent $String; } } } ::array unset _nplSetupPArray; ::array set _nplSetupPArray { {.trade_tax/1.expense_or_refund_account} {} {.trade_tax/1.description} {} {.trade_tax/1.rate} {0} {.trade_tax/1.is_charged} {no} {.trade_tax/1.otherAccountPrefix} {} {.trade_tax/1.is_included_in_cost} {no} {.trade_tax/2.expense_or_refund_account} {} {.trade_tax/2.description} {} {.trade_tax/2.rate} {0} {.trade_tax/2.is_charged} {no} {.trade_tax/2.otherAccountPrefix} {} {.trade_tax/2.is_included_in_cost} {no} {.trade_tax/2.is_compounded} {no} {.trade_tax.processed_indicator} {} {.purchase_journals} {} {.banks} {} {.terms.discount_days} {0} {.terms.discount_rate} {0} {.terms.due_days} {30} } ::if {![procedureExists "SETUPP"]} {::return;} ::set ProcRecords [procedureRecords "SETUPP"]; ::set ProcSource [procedureSource "SETUPP"]; ::set ProcedureInfo [procedure_info $ProcSource]; ::set Library [::sargs::get $ProcedureInfo ".library"]; ::if {$Library ne "NV1"&&$Library ne "HST"} {::return;} ::set _purchase_tax_library $Library; ::array set Result [procedureSettingsParse "SETUPP" $ProcRecords]; ::array set Settings $Result(0); ::if {$_purchase_tax_library eq "HST"} { ::set _purchase_tax_library "NV1"; ::if {[::info exists Settings(.trade_tax/3.rate)]} { ::if {[::string index $Settings(.trade_tax/3.rate) 0] eq "T"} { ::set Rate [::string range $Settings(.trade_tax/3.rate) 1 end]; ::if {$Rate ne ""&&[::string is double $Rate]} { ::set _purchase_tax_library "HST"; } } } } ::switch $_purchase_tax_library { "NV1" { ::foreach Field { ".trade_tax/1.is_charged" ".trade_tax/2.is_charged" ".trade_tax/2.is_compounded" } { ::if {[::info exists Settings($Field)]} { ::switch -- [::string index $Settings($Field) 0] { "Y" {::set _nplSetupPArray($Field) "yes";} "N" {::set _nplSetupPArray($Field) "no";} } } } } "HST" { ::if {[::info exists Settings(.trade_tax/1.is_charged)]} { ::switch -- [::string index $Settings(.trade_tax/1.is_charged) 0] { "Y" {::set _nplSetupPArray(.trade_tax/1.is_charged) "yes";} "H" {::set _nplSetupPArray(.trade_tax/2.is_charged) "yes";} } } ::set Settings(.trade_tax/2.rate) $Settings(.trade_tax/3.rate); ::foreach Field { ".expense_or_refund_account" ".description" } { ::if {[::info exists Settings(.trade_tax/1$Field)]} { ::set Settings(.trade_tax/2$Field) $Settings(.trade_tax/1$Field); } else { ::set Settings(.trade_tax/2$Field) ""; } } ::foreach Field { ".trade_tax/2.is_compounded" } { ::if {[::info exists Settings($Field)]} { ::switch -- [::string index $Settings($Field) 0] { "Y" {::set _nplSetupPArray($Field) "yes";} "N" {::set _nplSetupPArray($Field) "no";} } } } } } ::foreach Field { ".trade_tax/1.expense_or_refund_account" ".trade_tax/1.description" ".trade_tax/1.rate" ".trade_tax/1.otherAccountPrefix" ".trade_tax/2.expense_or_refund_account" ".trade_tax/2.description" ".trade_tax/2.rate" ".trade_tax/2.otherAccountPrefix" ".trade_tax.processed_indicator" ".purchase_journals" ".banks" ".terms.discount_days" ".terms.discount_rate" ".terms.due_days" } { ::set Value ""; ::if {[::info exists Settings($Field)]} { ::set Value [::string trim $Settings($Field)]; } ::if {$Value ne ""} {::set _nplSetupPArray($Field) $Value}; } } method loadNplSetupS {} { ::array unset _nplSetupSArray; ::array set _nplSetupSArray { {.trade_tax/1.payable_account} {} {.trade_tax/1.description} {} {.trade_tax/1.rate} {0} {.trade_tax/1.is_charged} {no} {.trade_tax/1.Prefix} {} {.trade_tax/2.payable_account} {} {.trade_tax/2.description} {} {.trade_tax/2.rate} {0} {.trade_tax/2.is_charged} {no} {.trade_tax/2.Prefix} {} {.trade_tax/2.is_compounded} {no} {.sales_journals} {} {.banks} {} {.ExtendPriceXQuantity} {no} {.PromptForInvoiceInfo} {no} {.terms.discount_days} {0} {.terms.discount_rate} {0} {.terms.due_days} {30} {.terms.interest_rate} {0} } ::if {![procedureExists "SETUPS"]} {::return;} ::set ProcRecords [procedureRecords "SETUPS"]; ::set ProcSource [procedureSource "SETUPS"]; ::set ProcedureInfo [procedure_info $ProcSource]; ::set Library [::sargs::get $ProcedureInfo ".library"]; ::if {$Library ne "NV1"&&$Library ne "HST"} {::return;} ::set _sales_tax_library $Library; ::array set Result [procedureSettingsParse "SETUPS" $ProcRecords]; ::array set Settings $Result(0); ::if {$_sales_tax_library eq "HST"} { ::set _sales_tax_library "NV1"; ::if {[::info exists Settings(.trade_tax/3.rate)]} { ::if {[::string index $Settings(.trade_tax/3.rate) 0] eq "T"} { ::set Rate [::string range $Settings(.trade_tax/3.rate) 1 end]; ::if {$Rate ne ""&&[::string is double $Rate]} { ::set _sales_tax_library "HST"; } } } } ::switch $_sales_tax_library { "NV1" { ::if {[::info exists Settings(.trade_tax/1.is_charged)]} { ::if {[::string index $Settings(.trade_tax/1.is_charged) 0] eq "T"} { ::set _nplSetupSArray(.trade_tax/1.is_charged) "yes"; } } ::if {[::info exists Settings(.trade_tax/2.is_charged)]} { ::if {[::string index $Settings(.trade_tax/2.is_charged) 0] eq "T"} { ::set _nplSetupSArray(.trade_tax/2.is_charged) "yes"; } } ::if {[::info exists Settings(.trade_tax/2.is_compounded)]} { ::if {[::string index $Settings(.trade_tax/2.is_compounded) 0] eq "Y"} { ::set _nplSetupSArray(.trade_tax/2.is_compounded) "yes"; } } } "HST" { ::if {[::info exists Settings(.trade_tax/1.is_charged)]} { ::switch -- [::string index $Settings(.trade_tax/1.is_charged) 0] { "Y" { ::set _nplSetupSArray(.trade_tax/1.is_charged) "yes"; } "H" { ::set _nplSetupSArray(.trade_tax/2.is_charged) "yes"; ::set Settings(.trade_tax/2.rate) $Settings(.trade_tax/3.rate); ::foreach Field { ".payable_account" ".description" } { ::if {[::info exists Settings(.trade_tax/1$Field)]} { ::set _nplSetupSArray(.trade_tax/2$Field) $Settings(.trade_tax/1$Field); } else { ::set _nplSetupSArray(.trade_tax/2$Field) ""; } } } } } } } ::foreach Field { ".trade_tax/1.payable_account" ".trade_tax/1.description" ".trade_tax/1.rate" ".trade_tax/1.Prefix" ".trade_tax/2.payable_account" ".trade_tax/2.description" ".trade_tax/2.rate" ".trade_tax/2.Prefix" ".trade_tax/3.rate" ".sales_journals" ".banks" ".ExtendPriceXQuantity" ".PromptForInvoiceInfo" ".terms.discount_days" ".terms.discount_rate" ".terms.due_days" ".terms.interest_rate" } { ::set Value ""; ::if {[::info exists Settings($Field)]} { ::set Value [::string trim $Settings($Field)]; } ::if {$Value ne ""} {::set _nplSetupSArray($Field) $Value}; } } method notes_fields_extract {Src Class} { ::if {![::info exists _accountNotesArray($Class)]} {::return "";} ::array set Result {}; ::set AccountNotes [[$Src ".notes"] odb_get]; ::set AccountNotes [::split $AccountNotes \n]; ::foreach Vector $_accountNotesArray($Class) { ::foreach {Name Row Start Length} $Vector {}; ::set End [::expr $Start+$Length-1]; ::set String [::string range [::lindex $AccountNotes $Row] $Start $End]; ::set String [::string trimleft [::string trimright $String]]; ::set Result($Name) $String; } ::return [::array get Result]; } method records_fields_extract {Src Class} { ::if {![::info exists _accountRecordsArray($Class)]} {::return "";} ::array set Result {}; ::array set AccountRecords [[$Src ".records"] odb_get]; ::set BaseRecord $_accountRecordsArray($Class-base); ::foreach Vector $_accountRecordsArray($Class) { ::foreach {Name Row Start Length} $Vector {}; ::set End [::expr $Start+$Length-1]; ::set RecordNumber [largeAdd $Row $BaseRecord]; ::set String ""; ::if {![::info exists AccountRecords($RecordNumber)]} {::continue;} ::set String [::string range $AccountRecords($RecordNumber) $Start $End]; ::set String [::string trimleft [::string trimright $String]]; ::if {[::info exists Result($Name)]} { ::if {$String ne ""} {::set Result($Name) "$Result($Name) $String";} } else { ::set Result($Name) $String; } } ::return [::array get Result]; } method fields_extract {Src Class} { ::if {![::info exists _accountNotesArray($Class)]} {::return "";} ::array set Result {}; ::foreach Vector $_accountNotesArray($Class) { ::set AccountNotes [[$Src ".notes"] odb_get]; ::set AccountNotes [::split $AccountNotes \n]; ::foreach {Name Row Start Length} $Vector {}; ::set End [::expr $Start+$Length-1]; ::set String [::string range [::lindex $AccountNotes $Row] $Start $End]; ::set String [::string trimleft [::string trimright $String]]; ::if {$String!=""} {::set Result($Name) [::string range [::lindex $AccountNotes $Row] $Start $End];} } ::return [::array get Result]; } method class_array_create {ClassRecordList} { ::array set Result {}; ::foreach Class {GENERAL BANK AP AR INVENTORY SALES EXPENSE CGS} { ::set Result($Class) 0; ::set Result($Class-reports) ""; } ::foreach {RecordNumber RecordData} $ClassRecordList { ::if {![::string is integer $RecordNumber]} {::continue;} ::if {$RecordNumber<100||$RecordNumber>=600} {::continue;} ::set Digit [::string range $RecordNumber 0 0]; ::set ReportClass [::lindex {{} AP AR EXPENSE SALES GENERAL INVENTORY CGS} $Digit]; ::if {$ReportClass==""} {continue;} ::set ReportList [::split $RecordData ","]; ::foreach Report $ReportList { ::if {$Report==""||[::string first "/xfe" $Report]==-1} {::continue;} ::set Items [::split $Report "/xfe"]; ::set ReportName [::lindex $Items 0]; ::set NormalBalance [::lindex $Items end]; ::if {$NormalBalance=="C"||$NormalBalance=="D"} { ::set Result($ReportName-$NormalBalance) $ReportClass; ::if {[reportExists $ReportName]} { ::incr Result($ReportClass); ::lappend Result($ReportClass-reports) [nameFilter $ReportName]; } } } } ::return [::array get Result]; } method copyNplSetup {} { ::set Dest [$_manager "/OBJECT/NEWVIEWS/JOURNAL/PURCHASE"]; ::foreach FieldName { ".trade_tax/1.is_charged" ".trade_tax/2.is_charged" ".trade_tax/2.is_compounded" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { [$Dest $FieldName] odb_set $_nplSetupPArray($FieldName); } } ::foreach FieldName { ".trade_tax/1.expense_or_refund_account" ".trade_tax/2.expense_or_refund_account" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { ::if {[accountExists $_nplSetupPArray($FieldName)]} { [$Dest $FieldName] odb_set [accountOdbAddressFromName $_nplSetupPArray($FieldName)]; } } } ::foreach FieldName { ".trade_tax/1.description" ".trade_tax/1.registration_id" ".trade_tax/2.description" ".trade_tax/2.registration_id" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { [$Dest $FieldName] odb_set $_nplSetupPArray($FieldName); } } ::if {[::info exists _nplSetupPArray(.trade_tax/1.rate)]} { setTaxStatusAndRateJournal -src $_nplSetupPArray(.trade_tax/1.rate) -dest $Dest -name ".trade_tax/1"; } ::if {[::info exists _nplSetupPArray(.trade_tax/2.rate)]} { setTaxStatusAndRateJournal -src $_nplSetupPArray(.trade_tax/2.rate) -dest $Dest -name ".trade_tax/2"; } [$Dest ".trade_tax/1.rebate_percent"] odb_set $_gst_rebate_percent; ::if {$_purchase_tax_library eq "HST"} { [$Dest ".trade_tax/2.rebate_percent"] odb_set $_gst_rebate_percent; } else { [$Dest ".trade_tax/2.rebate_percent"] odb_set "100"; } commit $Dest; ::set Dest [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/AP"]; ::foreach FieldName { ".trade_tax/1.is_charged" ".trade_tax/2.is_charged" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { [$Dest $FieldName] odb_set $_nplSetupPArray($FieldName); } } ::foreach FieldName { ".trade_tax/1.registration_id" ".trade_tax/2.registration_id" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { [$Dest $FieldName] odb_set $_nplSetupPArray($FieldName); } } ::foreach FieldName { ".terms.discount_days" ".terms.discount_rate" ".terms.due_days" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { ::set Value $_nplSetupPArray($FieldName); ::if {$Value ne ""&&[::string is double $Value]} { [$Dest $FieldName] odb_set $Value; } } } commit $Dest; ::set Dest [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/INVENTORY"]; ::foreach FieldName { ".trade_tax/1.expense_or_refund_account" ".trade_tax/2.expense_or_refund_account" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { ::if {[accountExists $_nplSetupPArray($FieldName)]} { [$Dest $FieldName] odb_set [accountOdbAddressFromName $_nplSetupPArray($FieldName)]; } } } ::if {[::info exists _nplSetupPArray(.trade_tax/1.rate)]} { setTaxStatusAndRate -src $_nplSetupPArray(.trade_tax/1.rate) -dest $Dest -name ".trade_tax/1"; } ::if {[::info exists _nplSetupPArray(.trade_tax/2.rate)]} { setTaxStatusAndRate -src $_nplSetupPArray(.trade_tax/2.rate) -dest $Dest -name ".trade_tax/2"; } commit $Dest; ::set Dest [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/EXPENSE"]; ::foreach FieldName { ".trade_tax/1.expense_or_refund_account" ".trade_tax/2.expense_or_refund_account" } { ::if {[::info exists _nplSetupPArray($FieldName)]} { ::if {[accountExists $_nplSetupPArray($FieldName)]} { [$Dest $FieldName] odb_set [accountOdbAddressFromName $_nplSetupPArray($FieldName)]; } } } ::if {[::info exists _nplSetupPArray(.trade_tax/1.rate)]} { setTaxStatusAndRate -src $_nplSetupPArray(.trade_tax/1.rate) -dest $Dest -name ".trade_tax/1"; } ::if {[::info exists _nplSetupPArray(.trade_tax/2.rate)]} { setTaxStatusAndRate -src $_nplSetupPArray(.trade_tax/2.rate) -dest $Dest -name ".trade_tax/2"; } commit $Dest; ::set Dest [$_manager "/OBJECT/NEWVIEWS/JOURNAL/SALES"]; ::foreach FieldName { ".trade_tax/1.is_charged" ".trade_tax/2.is_charged" ".trade_tax/2.is_compounded" } { ::if {[::info exists _nplSetupSArray($FieldName)]} { [$Dest $FieldName] odb_set $_nplSetupSArray($FieldName); } } ::foreach FieldName { ".trade_tax/1.payable_account" ".trade_tax/2.payable_account" } { ::if {[::info exists _nplSetupSArray($FieldName)]} { ::if {[accountExists $_nplSetupSArray($FieldName)]} { [$Dest $FieldName] odb_set [accountOdbAddressFromName $_nplSetupSArray($FieldName)]; } } } ::foreach FieldName { ".trade_tax/1.description" ".trade_tax/2.description" } { ::if {[::info exists _nplSetupSArray($FieldName)]} { [$Dest $FieldName] odb_set $_nplSetupSArray($FieldName); } } ::if {[::info exists _nplSetupSArray(.trade_tax/1.rate)]} { setTaxStatusAndRateJournal -src $_nplSetupSArray(.trade_tax/1.rate) -dest $Dest -name ".trade_tax/1"; } ::if {[::info exists _nplSetupSArray(.trade_tax/2.rate)]} { setTaxStatusAndRateJournal -src $_nplSetupSArray(.trade_tax/2.rate) -dest $Dest -name ".trade_tax/2"; } commit $Dest; ::set Dest [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/AR"]; ::foreach FieldName { ".trade_tax/1.is_charged" ".trade_tax/2.is_charged" } { ::if {[::info exists _nplSetupSArray($FieldName)]} { [$Dest $FieldName] odb_set $_nplSetupSArray($FieldName); } } ::foreach FieldName { ".terms.discount_days" ".terms.due_days" ".terms.interest_rate" ".terms.discount_rate" } { ::if {[::info exists _nplSetupSArray($FieldName)]} { ::set Value $_nplSetupSArray($FieldName); ::if {$Value ne ""&&[::string is double $Value]} { [$Dest $FieldName] odb_set $Value; } } } commit $Dest; ::set Dest [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/SALES"]; ::foreach FieldName { ".trade_tax/1.payable_account" ".trade_tax/2.payable_account" } { ::if {[::info exists _nplSetupSArray($FieldName)]} { ::if {[accountExists $_nplSetupSArray($FieldName)]} { [$Dest $FieldName] odb_set [accountOdbAddressFromName $_nplSetupSArray($FieldName)]; } } } ::if {[::info exists _nplSetupSArray(.trade_tax/1.rate)]} { setTaxStatusAndRate -src $_nplSetupSArray(.trade_tax/1.rate) -dest $Dest -name ".trade_tax/1"; } ::if {[::info exists _nplSetupSArray(.trade_tax/2.rate)]} { setTaxStatusAndRate -src $_nplSetupSArray(.trade_tax/2.rate) -dest $Dest -name ".trade_tax/2"; } commit $Dest; ::if {[procedureExists "COMPANY"]} { ::array set CompanySettingsAll [procedureSettingsParse "COMPANY" [procedureRecords "COMPANY"]]; ::array set Fields $CompanySettingsAll(0); ::set CompanyName ""; ::if {[::info exists Fields(.companyName)]} { ::set CompanyName [::string trim $Fields(.companyName)]; ::if {$CompanyName ne ""} { [$_manager "/OBJECT.description"] odb_set $CompanyName; commit [$_manager "/OBJECT"]; } } ::set Dest [$_manager "/OBJECT/NEWVIEWS/ACCOUNT"]; ::if {$CompanyName ne ""} {[$Dest ".address.company"] odb_set $CompanyName;} ::set Address ""; ::for {::set i 1;} {$i<=5} {::incr i;} { ::set Text ""; ::if {[::info exists Fields(.companyAddress$i)]} {::set Text $Fields(.companyAddress$i);} ::append Address $Text\n; } ::set Address [::string trimright $Address]; ::if {$Address ne ""} {[$Dest ".address.freeform"] odb_set $Address;} ::if {[::info exists Fields(.companyPhone)]} { [$Dest ".address.phone.freeform"] odb_set $Fields(.companyPhone); } ::if {[::info exists Fields(.companyFax)]} { [$Dest ".address.phone/fax.freeform"] odb_set $Fields(.companyFax); } commit $Dest; } copyPRTPAYSettings; } method copyPRTPAYSettings {} { ::set FieldNameList { .payInvoicesDueUpTo .payUpToDate date .dateOfChecks .checkDate date .nextCheckNumber .checkNumber string .bankJournal .bankJournal journal .bankAccount .bankAccount account .discountAccount .discountAccount account .pagePause {} {} .suppressPrinting .print !bool .confirmInvoices .confirmEachInvoice bool .confirmSuppliers .confirmEachSupplier bool .promptForAddresses {} {} .paymentsOnTerms .payAccordingToTerms bool .takeDiscounts .takeDiscounts bool .holdInvoicesText .holdInvoiceIndicatorText string .nameOfTemplate {} {} .previewMode {} {} .advanceRefOnVoidChecks .advanceReference bool .takeDiscountsOnTax1 .takeDiscountsOnTax1 bool .takeDiscountsOnTax2 .takeDiscountsOnTax2 bool } ::array set ProcSettingsArray {}; ::if {[procedureExists "PRTPAY"]} { ::set ProcRecords [procedureRecords "PRTPAY"]; ::array set ProcSettingsArray [procedureSettingsParse "PRTPAY" $ProcRecords]; } ::set ProcStructure ""; ::for {::set i 0;} {$i<=100} {::incr i;} { ::if {![::info exists ProcSettingsArray($i)]} {::break;} ::catch {::array unset NplSetupArray}; ::array set NplSetupArray $ProcSettingsArray($i); ::if {![::info exists NplSetupArray(.balancingBankAccount)]} {::set NplSetupArray(.balancingBankAccount) ""} ::if {![::info exists NplSetupArray(.bankOrJournalAccount)]} {::set NplSetupArray(.bankOrJournalAccount) ""} ::set Account ""; ::set Journal ""; ::if {$NplSetupArray(.balancingBankAccount) ne ""} { ::set Account $NplSetupArray(.balancingBankAccount); ::set Journal $NplSetupArray(.bankOrJournalAccount); } else { ::set Account $NplSetupArray(.bankOrJournalAccount); } ::set NplSetupArray(.bankAccount) $Account; ::set NplSetupArray(.bankJournal) $Journal; ::unset NplSetupArray(.balancingBankAccount); ::unset NplSetupArray(.bankOrJournalAccount); ::set NplSetupArray(.takeDiscountsOnTax1) "yes"; ::set NplSetupArray(.takeDiscountsOnTax2) "yes"; ::if {[procedureExists "PRTPAY"]} { ::if {[::string first "@DISCONTAX=N" [::lindex [procedureNotes "PRTPAY"] 0]]>=0} { ::set NplSetupArray(.takeDiscountsOnTax1) "no"; } } ::catch {::unset Result}; ::set Settings ""; ::set Confirm1 "yes"; ::set Confirm2 "yes"; ::foreach {DOSName NV2Name Type} $FieldNameList { ::if {$DOSName eq "" || $NV2Name eq ""} {::continue;} ::set Data ""; ::if {[::info exists NplSetupArray($DOSName)]} {::set Data $NplSetupArray($DOSName);} ::set Result ""; ::switch $Type { "string" {::set Result $Data;} "date" { ::if {[is_valid_nv1_date $Data]} { ::set Result [nv1_keystroke_to_ymdhms $Data]; ::set Result [pgq_date_fix $Result]; } else { ::set Result [::qw::date::null]; } } "bool" { ::set Result "no"; ::if {$Data ne "" && [::string is boolean $Data] && $Data} {::set Result "yes";} } "!bool" { ::set Result "yes"; ::if {$Data ne "" && [::string is boolean $Data] && $Data} {::set Result "no";} } "account" { ::if {$Data ne "" && [accountExists $Data]} { ::set Result [accountOdbAddressFromName $Data]; } } "journal" { ::if {$Data ne ""} { ::set Result [[$_manager "/OBJECT/NEWVIEWS/JOURNAL/GENERAL$_slashIdPrefix/DOSIMPORT/JOURNAL_ACCOUNTS.odb_deriveds.index/name"] odb_find_key ".name" $Data]; ::if {$Result ne ""} {::set Result [[$Result odb_master] odb_address];} } } } ::if {$DOSName eq ".confirmInvoices"} {::set Confirm1 $Result;::continue;} ::if {$DOSName eq ".confirmSuppliers"} {::set Confirm2 $Result;::continue;} ::sargs::var::set Settings $NV2Name $Result; } ::if {$Confirm1 || $Confirm2} {::sargs::var::set Settings ".confirmPayments" "yes";} ::if {$i==0} { ::sargs::var::set ProcStructure "/default.name" "*** Default Settings ***"; ::sargs::var::set ProcStructure "/default.values" $Settings; ::continue; } ::sargs::var::set ProcStructure "/$i.name" $NplSetupArray(.name); ::sargs::var::set ProcStructure "/$i.values" $Settings; } [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/AP.settings_prompt"] odb_set [::sargs::set [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/AP.settings_prompt"] qw_get] "/prtpay" $ProcStructure]; commit [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/AP"]; } method BLKCOPYSettings {Base} { ::set Result ""; ::if {![procedureExists "BLKPASTE"]} {::return $Result;} ::array set RecordArray [procedureRecords "BLKPASTE"]; ::set SettingsList ""; ::set Names ""; ::for {set i 0} {$i<=24} {::incr i} { ::set RecordNumber [largeAdd $Base $i]; ::if {![::info exists RecordArray($RecordNumber)]} {::break;} ::append Names $RecordArray($RecordNumber); } ::set Pointers ""; ::for {set i 50} {$i<=52} {::incr i} { ::set RecordNumber [largeAdd $Base $i]; ::if {![::info exists RecordArray($RecordNumber)]} {::break;} ::append Pointers $RecordArray($RecordNumber); } ::if {[::string length $Names]!=[::expr [::string length $Pointers]*10]} { import_error "CONVERT_NV1_TO_NV2 Error in saved settings Names/Pointers for procedure BLKCOPY"; } ::for {set i 0;set j 0;} {$i<[::string length $Pointers]} {::incr i 3;::incr j 30;} { ::set BaseRecord [::string trimright [::string range $Pointers $i [::expr $i+2]]]; ::if {$BaseRecord==""} {::break} ::set BaseRecord "[::string index $Base 0]$BaseRecord"; ::append BaseRecord "000000"; ::set Name [::string trimright [::string range $Names $j [::expr $j+29]]] ::lappend SettingsList [::list $Name $BaseRecord]; } ::set Count 0; ::foreach NamedSetting $SettingsList { ::set SettingName [::lindex $NamedSetting 0]; ::set RecordNumber [::lindex $NamedSetting 1]; ::sargs::var::set Result "/$Count" {}; ::sargs::var::set Result "/$Count.name" $SettingName; ::sargs::var::set Result "/$Count.records" {}; ::set Records ""; ::while {1} { ::if {![::info exists RecordArray($RecordNumber)]} {::break;} ::lappend Records $RecordArray($RecordNumber); ::set RecordNumber [largeAdd $RecordNumber 1]; } ::sargs::var::set Result "/$Count.records" $Records; ::incr Count; } ::return $Result; } method convert_slashx_characters {Src} { ::while {[::regexp {(/x[0-9a-hA-H][0-9a-hA-H])} $Src match]} { ::set Replace [::subst [::string map "/ \\" $match]]; ::set Src [::regsub -all $match $Src $Replace]; } ::return $Src } method string_printable {Src Replace} { ::set Result ""; ::foreach Character [::split $Src ""] { ::binary scan $Character c byte1d; ::set CharacterNumber [::expr ($byte1d + 0x100) % 0x100]; ::if {$CharacterNumber>=32&&$CharacterNumber<=127} { ::append Result $Character; } else { ::append Result $Replace; } } ::return $Result; } method copyBLKCOPYSettings {} { ::return ""; ::set Settings [BLKCOPYSettings 1000000000]; ::set Result ""; ::set Transaction ""; ::set Notes ""; ::set Distributions 0; ::set SubCount 0; ::foreach Sub [::sargs::subs .structure $Settings] { ::set Count 0; ::sargs::var::set Result "/transaction.settings/$SubCount.name" [::sargs::get $Settings $Sub.name]; ::sargs::var::set Result "/transaction.settings/$SubCount.values" ""; ::foreach Record [::sargs::get $Settings $Sub.records] { ::set Record [convert_slashx_characters $Record]; ::switch [::string index $Record 0] { "\x7f" { ::set Record [string_printable $Record *]; ::if {$Transaction ne ""} { ::sargs::var::set Transaction ".notes.qw_get" $Notes; ::sargs::var::set Result "/transaction.settings/$SubCount.values/$Count" $Transaction; ::incr Count; } ::set Date [nv1_keystroke_to_ymdhms [::string range $Record 1 8]]; ::set Reference [::string trim [::string range $Record 9 15]]; ::set Description [::string trimright [::string range $Record 16 45]]; ::set Account [::string trimright [::string range $Record 57 66]]; ::set Amount [::string range $Record 46 56]; ::set Amount [::qw::number::scan [::string range $Record 46 56]]; ::set Transaction ""; ::set Notes ""; ::set Distributions 0; ::sargs::var::set Transaction ".date.qw_get" $Date; ::sargs::var::set Transaction ".reference.qw_get" $Reference; ::sargs::var::set Transaction ".description.qw_get" $Description; ::if {$Account ne ""&&[accountExists $Account]} { ::set Class $_account_class_array($Account); ::if {$Class ne "TOTAL"} { ::set Account [account_get $Account]; ::set NormalBalance [$Account normal_balance_get]; ::set Posting "debit"; ::sargs::var::set Transaction ".posting/$Posting.account.qw_get" [$Account odb_address]; ::sargs::var::set Transaction ".posting/$Posting.amount.qw_get" $Amount; } } } "\xcd" { ::set Record [string_printable $Record *]; ::set Account [::string trimright [::string range $Record 1 10]]; ::set Description [::string trimright [::string range $Record 11 40]]; ::set Amount [::string range $Record 41 52]; ::set Amount [::qw::number::scan [::string range $Record 41 52]]; ::set Distribution ""; ::if {$Account ne ""&&[accountExists $Account]} { ::set Class $_account_class_array($Account); ::if {$Class ne "TOTAL"} { ::set Account [account_get $Account]; ::set NormalBalance [$Account normal_balance_get]; ::set Posting "debit"; ::sargs::var::set Distribution ".posting/$Posting.account.qw_get" [$Account odb_address]; ::sargs::var::set Distribution ".posting/$Posting.amount.qw_get" $Amount; } } ::sargs::var::set Distribution ".description.qw_get" $Description; ::sargs::var::set Transaction /$Distributions $Distribution; ::incr Distributions; } default {::lappend Notes $Record;} } } ::if {$Transaction ne ""} { ::sargs::var::set Transaction ".notes.qw_get" $Notes; ::sargs::var::set Result "/transaction.settings/$SubCount.values/$Count" $Transaction; ::set Transaction ""; } ::incr SubCount; } ::set Settings [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/TRANSACTION.paste_buffer"] qw_get]; ::set Settings [BLKCOPYSettings 2000000000]; ::set Result ""; ::set Account ""; ::set SubCount 0; ::foreach Sub [::sargs::subs .structure $Settings] { ::set Report ""; ::foreach Record [::sargs::get $Settings $Sub.records] { ::set Record [convert_slashx_characters $Record]; ::if {[::string index $Record 0] ne "\x7f"} { ::continue; } ::set Name [::string trimright [::string range $Record 33 42]]; ::if {$Name eq ""} {::continue;} ::if {[accountExists $Name]} { ::set Account [account_get $Name]; ::set Report [[$Account ".report"] odb_get]; ::break; } } ::set Count 0; ::set Notes ""; ::set Account ""; ::sargs::var::set Result "/account.settings/$SubCount.name" [::sargs::get $Settings $Sub.name]; ::sargs::var::set Result "/account.settings/$SubCount.values" ""; ::foreach Record [::sargs::get $Settings $Sub.records] { ::set Record [convert_slashx_characters $Record]; ::if {[::string index $Record 0] ne "\x7f"} { ::lappend Notes $Record; ::continue; } ::set Record [string_printable $Record *]; ::if {$Account ne ""} { ::sargs::var::set Account ".notes.qw_get" $Notes; ::sargs::var::set Result "/account.settings/$SubCount.values/$Count" $Account; ::set Account ""; ::incr Count; } ::set Description [::string trimright [::string range $Record 1 30]]; ::set SetupColumn [::string trimright [::string index $Record 31]]; ::set Underline [::string trimright [::string index $Record 32]]; ::set Name [::string trimright [::string range $Record 33 42]]; ::set NormalBalance [::string trimright [::string index $Record 43]]; ::set Total(1) [::string trimright [::string range $Record 44 53]]; ::set Total(2) [::string trimright [::string range $Record 54 63]]; ::set Notes ""; ::set Account ""; ::sargs::var::set Account ".description.qw_get" $Description; ::sargs::var::set Account ".report.qw_get" $Report; ::if {$Name ne ""} { ::sargs::var::set Account ".name.qw_get" $Name; ::sargs::var::set Account ".line_type" "account"; ::sargs::var::set Account ".normal_balance.odb_get" [::expr [::string equal $NormalBalance "D"]?"debit":"credit"]; ::sargs::var::set Account ".setup_column.qw_get" $SetupColumn; ::sargs::var::set Account ".setup_underline.qw_get" $Underline; ::if {[accountExists $Name]} { ::sargs::var::set Account ".odb_address" [account_get $Name]; ::sargs::var::set Account ".odb_base.qw_get" [[[account_get $Name] ".odb_base"] odb_get]; } else { ::sargs::var::set Account ".odb_address" ""; ::sargs::var::set Account ".odb_base.qw_get" [$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"]; } ::foreach i {1 2} { ::if {$Total($i) ne ""&&[accountExists $Total($i)]} { ::set Class $_account_class_array($Total($i)); ::if {$Class eq "TOTAL"} { ::set Total($i) [account_get $Total($i)]; ::sargs::var::set Account ".total.parent$i.qw_get" [$Total($i) odb_address]; } } } } else { ::sargs::var::set Account ".line_type" "text_line"; ::sargs::var::set Account ".odb_address" ""; ::sargs::var::set Account ".odb_base.qw_get" [$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"]; } } ::if {$Account ne ""} { ::sargs::var::set Account ".notes.qw_get" $Notes; ::sargs::var::set Result "/account.settings/$SubCount.values/$Count" $Account; } ::incr SubCount; } ::set Settings [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.paste_buffer"] qw_get]; [$_manager "/OBJECT/NEWVIEWS/ACCOUNT.paste_buffer"] odb_set [::sargs::set $Settings "/blkcopy" $Result]; ::return; } public method copySETUPIsettings {} { ::if {![procedureExists "SETUPI"]} {::return $this;} ::array set ProcSettingsArray {}; ::set ProcRecords [procedureRecords "SETUPI"]; ::array set ProcSettingsArray [procedureSettingsParse "SETUPI" $ProcRecords]; ::if {![::info exists ProcSettingsArray(0)]} {::return $this;} ::array set Settings $ProcSettingsArray(0); ::set Master [$_manager "/OBJECT/NEWVIEWS/JOURNAL/SALES"]; ::set InvoiceInfo [[$Master ".invoice_information"] qw_get]; ::for {::set i 1;} {$i<=12} {::incr i;} { ::set Name "" ::set Value ""; ::if {[::info exists Settings(.prompt$i)]} {::set Name $Settings(.prompt$i);} ::if {[::info exists Settings(.default$i)]} {::set Value $Settings(.default$i);} ::sargs::var::set InvoiceInfo "/$i.name" $Name; ::sargs::var::set InvoiceInfo "/$i.value" $Value; } [$Master ".invoice_information"] odb_set $InvoiceInfo; commit $Master; } public method setTaxStatusAndRate {args} { ::array set Args $args; ::if {[::string trim $Args(-src)] eq ""} {::return;} ::switch -- [::string range $Args(-src) 0 0] { "T" {[$Args(-dest) "$Args(-name).status"] odb_set "taxable";} "X" {[$Args(-dest) "$Args(-name).status"] odb_set "exempt";} default {::set Args(-src) "";} } ::set Rate [::string range $Args(-src) 1 end] ::if {$Rate ne ""&&[::string is double $Rate]} { [$Args(-dest) "$Args(-name).rate"] odb_set $Rate; } ::return $this; } public method setTaxStatusAndRateJournal {args} { ::array set Args $args; ::if {[::string trim $Args(-src)] eq ""} {::return;} ::switch -- [::string range $Args(-src) 0 0] { "T" {[$Args(-dest) "$Args(-name).status"] odb_set "taxable";} "X" {[$Args(-dest) "$Args(-name).status"] odb_set "exempt";} default {::set Args(-src) "";} } ::set Rate [::string range $Args(-src) 1 end] ::if {$Rate ne ""&&[::string is double $Rate]} { [$Args(-dest) "$Args(-name).rate"] odb_set $Rate; } ::return $this; } method total_government_totals_accounts_destroy {} { ::append _payroll_convert_notes "DELETING TOTAL GT ACCOUNTS\n"; ::switch -- $_payrollCountry { "CANADA" { ::set List {\ .totalInsurableEarningsAccount \ .totalInsurableHoursAccount \ .totalPensionableEarningsAccount \ .totalHSFEarningsAccount \ .totalPPIPInsurableEarningsAccount \ } } "USA" { ::set List {\ .totalFutaAccount \ } } default {import_error "Unknown country $_payrollCountry";} } ::set Report ""; ::foreach Item $List { ::foreach AccountName [payrollInfoLoad $Item] { ::if {![::info exists _account_class_array($AccountName)]} {::continue;} ::set Account [account_get $AccountName]; ::if {[[$Account ".postings"] odb_items]!=0} { ::append _payroll_convert_notes "* Cannot remove total GT account $AccountName, account contains [[$Account .postings] odb_items] postings.\n"; status "Remove total GT account $AccountName failed, account contains [[$Account .postings] odb_items] postings."; ::continue; } ::append _payroll_convert_notes "Total GT account $AccountName deleted.\n"; status "Removing total GT account $AccountName."; ::if {$Report eq ""} {::set Report [[$Account ".report"] odb_get];} $Account odb_destroy; } } ::if {$Report ne ""} { ::set Report [$Report odb_master]; ::set Index [[$Report ".accounts"] ".index/interactive"]; ::set Accounts 0; ::set RefList ""; ::for {::set AccountRef [$Index odb_first]} {$AccountRef ne ""} {::set AccountRef [$Index odb_next $AccountRef]} { ::if {[[[$AccountRef odb_master] ".line_type"] odb_get] ne "text_line"} {::incr Accounts;::break;} ::lappend RefList $AccountRef; } ::if {$Accounts==0} { ::foreach Ref $RefList { [$Ref odb_master] odb_destroy; } $Report odb_destroy; } } ::append _payroll_convert_notes "\n"; ::return $this; } method employee_accounts_check {} { ::if {!$_payroll_is_installed} {::return $this;} ::array set AccountArray {}; ::set Index [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/${_payrollCountry}.odb_deriveds.index/name"]; ::for {::set Ref [$Index odb_first];} {$Ref ne ""} {::set Ref [$Index odb_next $Ref];} { ::set Account [$Ref odb_master]; ::set Name [[$Account .name] odb_get]; status "Checking employee accounts: $Name"; ::if {[[$Account ".employee"] odb_get] eq ""} { ::set AccountArray($Name) $Account; status "WARNING: EMPLOYEE account $Name - employee ref is empty." } } ::foreach Name [::array names AccountArray] { status "Converting payroll account $Name to general." change_account_class $AccountArray($Name) "GENERAL" "GENERAL"; } ::return $this; } method employee_accounts_cleanup {} { ::append _payroll_convert_notes "EMPLOYEE ACCOUNTS CLEANUP\n"; ::set EmployeeIndex [$_manager "/OBJECT/NEWVIEWS/SYSTEM/EMPLOYEE/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/id"]; ::set PayrollAccountsIndex [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"]; ::set TotalAccountsIndex [$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"]; ::for {::set EmployeeRef [$EmployeeIndex odb_first];} {$EmployeeRef ne ""} {::set EmployeeRef [$EmployeeIndex odb_next $EmployeeRef];} { ::set Employee [$EmployeeRef odb_master]; status "Checking accounts for employee [[$Employee .name] odb_get]"; ::set Import_Datum [[$Employee ".import_datum"] odb_get]; ::set Import_Datum [employee_government_totals_accounts_destroy $Employee $Import_Datum]; ::if {[::sargs::exists $Import_Datum ".benefits"]} { ::set Import_Datum [employee_benefits_accounts_destroy $Employee $Import_Datum]; } [$Employee ".import_datum"] odb_set $Import_Datum; ::if {![is_employee_active $Employee]} { [$Employee ".active"] odb_set "inactive"; } ::set EmployeeAccountsIndex [$Employee ".accounts.index/name"]; ::set RefList ""; ::for {::set Ref [$EmployeeAccountsIndex odb_first];} {$Ref ne ""} {::set Ref [$EmployeeAccountsIndex odb_next $Ref];} { ::lappend RefList $Ref; } ::set EqualAccountList ""; ::foreach Ref $RefList { ::set Account [$Ref odb_master]; ::set Name [[$Account ".name"] odb_get]; ::if {$Name eq ""} {::continue;} ::set NameItems [splitAccountName $Name]; ::set Prefix [::lindex $NameItems 0]; ::set Separator [::lindex $NameItems 1]; ::set Suffix [::lindex $NameItems 2]; ::if {$Prefix eq ""||$Separator eq ""||$Suffix eq ""} { ::continue; } ::set Suffix [::regsub -all {([^0-9a-zA-Z])} $Suffix ""]; ::set Prefix [[$Employee ".employee_id"] odb_get]; ::set NewName $Prefix-$Suffix; ::if {$NewName eq $Name} { ::continue; } ::set Sub ""; ::if {[$Account is_total]} { ::set Index $TotalAccountsIndex; } else { ::set Index $PayrollAccountsIndex; } ::while {[$Index odb_find_key ".name" $NewName] ne ""} { ::if {$Sub eq ""} {::set Sub 1;} ::incr Sub; ::set NewName "$Prefix-$Suffix$Sub"; } status "Renaming account $Name to $NewName"; ::append _payroll_convert_notes "* Employee $Prefix, renaming account \"$Name\" to \"$NewName\"\n"; [$Account ".name"] odb_set $NewName; $Account odb_commit; ::if {$Separator eq "~"} { ::set EqualName [::string map "- =" $NewName]; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $EqualName]; ::if {$Reference ne ""} { ::lappend EqualAccountList [$Reference odb_master]; } else { ::set Object [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Object ".folder"] odb_set "file"; [$Object ".nplclass"] odb_set "PAYROLL"; [$Object ".name"] odb_set $EqualName; [$Object ".description"] odb_set [[$Account ".description"] odb_get]; [$Object ".normal_balance"] odb_set "credit"; [$Object ".setup_column"] odb_set [[$Account ".setup_column"] odb_get]; [$Object ".underline"] odb_set [[$Account ".underline"] odb_get]; [$Object ".report"] odb_set [[$Account ".report"] odb_get]; [$Object ".employee"] odb_set [[$Account ".employee"] odb_get]; $Object odb_commit; ::set _account_class_array($EqualName) "PAYROLL"; ::lappend EqualAccountList $Object; } } } ;#// end of foreach account loop ::if {[::llength $EqualAccountList]} { ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { ::set AW_maybe ""; ::set Id [[$Employee ".employee_id"] odb_get]; ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-AW"]; ::if {$AW_maybe eq ""} { ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.AW"]; } ::set ::qw::control(accrual_payroll_convert_on_the_fly) 0; employee_accounts_cleanup_accrual $Employee $EqualAccountList $AW_maybe; ::set ::qw::control(accrual_payroll_convert_on_the_fly) 1; } else { ::set AW_maybe ""; ::set Id [[$Employee ".employee_id"] odb_get]; ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-AW"]; ::if {$AW_maybe eq ""} { ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.AW"]; } employee_accounts_cleanup_accrual $Employee $EqualAccountList $AW_maybe; } } $Employee odb_commit; } ::append _payroll_convert_notes "\n"; } method employee_accounts_cleanup_accrual {Employee EqualAccountList AW_maybe} { ::if {$::qw::control(accrual_payroll_convert_xcld_vac_pay_total_to)} { ::return [employee_accounts_cleanup_accrual_xvp $Employee $EqualAccountList $AW_maybe]; } ::set Ofly $::qw::control(accrual_payroll_convert_on_the_fly); ::set Dcount 0; ::set Parent1 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 0]; ::set Parent2 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 1]; ::set Id [[$Employee ".employee_id"] odb_get]; ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { } ::set Account [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id=PAYABLE"]; ::if {$Account ne ""} { ::foreach EqualAccount $EqualAccountList { ::set Enotes [employee_accounts_cleanup_accrual_position_and_totalto $Employee $EqualAccount $AW_maybe $Account]; $EqualAccount odb_commit; } ::set Notes [[$Employee ".notes"] odb_get]; ::append Notes [::string map "$Id~ $Id-" $Enotes]; [$Employee ".notes"] odb_set $Notes; $Employee odb_commit; ::return; } ::set Enotes ""; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_first [$TextLine ".employee"]; ::set Account [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds"] odb_factory]; ::set NetPayableAccount $Account; [$Account ".name"] odb_set "$Id=NETPAYABLE"; [$Account ".description"] odb_set "Net Wages Payable incl. Vacation Pay"; [$Account ".normal_balance"] odb_set "credit"; [$Account ".setup_column"] odb_set 1; [$Account ".employee"] odb_set [$Employee ".accounts"]; $Account odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$Account ".employee"] [$TextLine ".employee"]; ::append Enotes "\nCreated account name: [[$Account .name] odb_get]"; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$Account ".employee"]; ::append Enotes "\nCreated text line description:"; ::set PrevLine $TextLine; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "WAGES PAYABLE"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$PrevLine ".employee"]; ::append Enotes "\nCreated text line description: WAGES PAYABLE"; ::set Account [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Account ".name"] odb_set "$Id=PAYABLE"; [$Account ".description"] odb_set "Total Wages Payable"; [$Account ".normal_balance"] odb_set "credit"; [$Account ".setup_column"] odb_set 1; [$Account ".employee"] odb_set [$Employee ".accounts"]; [$Account ".total.$Parent2"] odb_set [$NetPayableAccount ".total.kids"]; ::append Enotes "\nCreated account name: [[$Account .name] odb_get]"; ::append Enotes "\n[[$Account .name] odb_get] .total.$Parent2 set to [[$NetPayableAccount .name] odb_get]"; $Account odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$Account ".employee"] [$TextLine ".employee"]; ::set PrevLine $TextLine; ::foreach EqualAccount $EqualAccountList { ::append Enotes [employee_accounts_cleanup_accrual_position_and_totalto $Employee $EqualAccount $AW_maybe $Account]; $EqualAccount odb_commit; ::set PrevLine $EqualAccount; } ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$Account ".employee"]; ::append Enotes "\nCreated text line description:"; ::set PrevLine $TextLine; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "WAGES PAID"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$PrevLine ".employee"]; ::append Enotes "\nCreated text line description: WAGES PAID"; ::set GROSS_maybe ""; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-REG"]; ::if {$Reference ne ""} { ::set GROSS_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } ::if {$GROSS_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.REG"]; ::if {$Reference ne ""} { ::set GROSS_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$GROSS_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id~REG"]; ::if {$Reference ne ""} { ::set GROSS_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$GROSS_maybe eq ""} { ::set GROSS_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-GROSS"]; } ::if {$GROSS_maybe eq ""} { ::set GROSS_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.GROSS"]; } ::if {$GROSS_maybe ne ""} { ::set GROSS_maybe [$GROSS_maybe odb_master]; [$GROSS_maybe ".total.$Parent2"] odb_set [$NetPayableAccount ".total.kids"]; $GROSS_maybe odb_commit; ::append Enotes "\n[[$GROSS_maybe .name] odb_get] .total.$Parent2 set to [[$NetPayableAccount .name] odb_get]"; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$GROSS_maybe ".employee"]; ::append Enotes "\nCreated text line description:"; ::set PrevLine $TextLine; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "DEDUCTIONS"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$PrevLine ".employee"]; ::append Enotes "\nCreated text line description: DEDUCTIONS"; } ::set DEDUCT_maybe ""; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-TAX"]; ::if {$Reference ne ""} { ::set DEDUCT_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } ::if {$DEDUCT_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.TAX"]; ::if {$Reference ne ""} { ::set DEDUCT_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$DEDUCT_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id~TAX"]; ::if {$Reference ne ""} { ::set DEDUCT_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$DEDUCT_maybe eq ""} { ::set DEDUCT_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-DEDUCT"]; } ::if {$DEDUCT_maybe eq ""} { ::set DEDUCT_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.DEDUCT"]; } ::if {$DEDUCT_maybe ne ""} { ::set DEDUCT_maybe [$DEDUCT_maybe odb_master]; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$DEDUCT_maybe ".employee"]; ::append Enotes "\nCreated text line description:"; } ::if {$AW_maybe ne ""} { ::set AW_maybe [$AW_maybe odb_master]; ::if {[[$AW_maybe ".employee"] odb_get] eq ""} { [$AW_maybe ".employee"] odb_set [$Employee ".accounts"]; $AW_maybe odb_commit; } } ::if {$AW_maybe eq ""} { ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-AW"]; } ::if {$AW_maybe eq ""} { ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.AW"]; } ::if {$AW_maybe ne ""} { ::set AW_maybe [$AW_maybe odb_master]; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_before [$TextLine ".employee"] [$AW_maybe ".employee"]; ::append Enotes "\nCreated text line description:"; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "NV1 TIMECARDS & PAYMENTS"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_before [$TextLine ".employee"] [$AW_maybe ".employee"]; ::append Enotes "\nCreated text line description: NV1 TIMECARDS & PAYMENTS"; } ::set Notes [[$Employee ".notes"] odb_get]; ::append Notes [::string map "$Id~ $Id-" $Enotes]; [$Employee ".notes"] odb_set $Notes; $Employee odb_commit; ::set Payroll [$_manager "/OBJECT/NEWVIEWS/PAYROLL/$_payrollCountry"]; ::set Notes [[$Payroll ".notes"] odb_get]; ::append Notes "\nEncountered Accrual Payroll Employee Id: $Id"; [$Payroll ".notes"] odb_set $Notes; $Payroll odb_commit; ::return; } method employee_accounts_cleanup_accrual_position_and_totalto {Employee EqualAccount AW_maybe PTaccount} { ::set Ofly $::qw::control(accrual_payroll_convert_on_the_fly); ::set Id [[$Employee ".employee_id"] odb_get]; ::set Dcount 100; ::set Parent1 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 0]; ::set Parent2 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 1]; ::if {$AW_maybe ne ""} { } ::set Enotes ""; [$Employee ".accounts.index/interactive"] odb_make_before [$EqualAccount ".employee"] [[$PTaccount odb_master] ".employee"]; [$EqualAccount ".total.$Parent1"] odb_set [[$PTaccount odb_master] ".total.kids"]; ::append Enotes "\n[[$EqualAccount .name] odb_get] .total.$Parent1 set to [[[$PTaccount odb_master] .name] odb_get]"; ::set AW_totalto ""; ::if {$AW_maybe ne ""} { ::set AW_maybe [$AW_maybe odb_master]; ::set AW_totalto [[$AW_maybe ".total.parent1"] odb_get]; ::if {$AW_totalto eq ""} { ::set AW_totalto [[$AW_maybe ".total.parent2"] odb_get]; } ::if {$AW_totalto ne ""} { ::set AW_totalto_totalto [[[$AW_totalto odb_master] ".total.parent1"] odb_get]; ::if {$AW_totalto_totalto eq ""} { ::set AW_totalto_totalto [[[$AW_totalto odb_master] ".total.parent2"] odb_get]; } ::if {$AW_totalto_totalto ne ""} { ::set AW_totalto $AW_totalto_totalto; } ::if {[[$EqualAccount ".total.parent2"] odb_get] eq ""} { [$EqualAccount ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; ::append Enotes "\n[[$EqualAccount .name] odb_get] .total.$Parent2 set to [[[$AW_totalto odb_master] .name] odb_get]"; } } } ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { ::set TildaName [::string map "= ~" [[$EqualAccount ".name"] odb_get]]; ::set TildaAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $TildaName]; } else { ::set HyphenName [::string map "= -" [[$EqualAccount ".name"] odb_get]]; ;#// it's still has the tilda name! ::set HyphenAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $HyphenName]; ::set TildaName $HyphenName; ::set TildaAccount $HyphenAccount; } ::if {$TildaAccount ne ""} { ::set TildaAccount [$TildaAccount odb_master]; ::set Report [[$TildaAccount ".report"] odb_get]; ::if {$Report ne ""} { [[$Report odb_master] ".accounts.index/interactive"] odb_make_before [$EqualAccount ".report"] [$TildaAccount ".report"]; } ::if {$AW_totalto ne ""} { ::set Tap2 [[$TildaAccount ".total.parent2"] odb_get]; ::if {$Tap2 eq ""} { [$TildaAccount ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; ::append Enotes "\n[[$TildaAccount .name] odb_get] .total.$Parent2 set to [[[$AW_totalto odb_master] .name] odb_get]"; } else { ::append Enotes "\n*** WARNING *** [[$TildaAccount .name] odb_get] .total.$Parent2 is already set to [[[$Tap2 odb_master] .name] odb_get]"; [$TildaAccount ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; ::append Enotes "\n\t[[$TildaAccount .name] odb_get] .total.$Parent2 set to [[[$AW_totalto odb_master] .name] odb_get]"; [$TildaAccount ".total.parent3"] odb_set $Tap2; ::append Enotes "\n\t[[$TildaAccount .name] odb_get] .total.parent3 set to [[[$Tap2 odb_master] .name] odb_get]"; } $TildaAccount odb_commit; } } ::return $Enotes; } method employee_accounts_cleanup_accrual_xvp {Employee EqualAccountList AW_maybe} { ::if {$AW_maybe ne ""} { } ::set Ofly $::qw::control(accrual_payroll_convert_on_the_fly); ::set Dcount 0; ::set Parent1 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 0]; ::set Parent2 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 1]; ::set Id [[$Employee ".employee_id"] odb_get]; ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { } ::if {$AW_maybe eq ""} { ::if {$AW_maybe eq ""} { ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-AW"]; } ::if {$AW_maybe eq ""} { ::set AW_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.AW"]; } } ::set AW_totalto ""; ::if {$AW_maybe ne ""} { ::set AW_maybe [$AW_maybe odb_master]; ::set AW_totalto [[$AW_maybe ".total.parent1"] odb_get]; ::if {$AW_totalto eq ""} { ::set AW_totalto [[$AW_maybe ".total.parent2"] odb_get]; } ::if {$AW_totalto ne ""} { ::set AW_totalto_totalto [[[$AW_totalto odb_master] ".total.parent1"] odb_get]; ::if {$AW_totalto_totalto eq ""} { ::set AW_totalto_totalto [[[$AW_totalto odb_master] ".total.parent2"] odb_get]; } ::if {$AW_totalto_totalto ne ""} { ::set AW_totalto $AW_totalto_totalto; } } } ::set Account [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id=PAYABLE"]; ::if {$Account ne ""} { ::foreach EqualAccount $EqualAccountList { ::set NetxvpAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id=NETXVP"]; ::set Enotes [employee_accounts_cleanup_accrual_position_and_totalto_xvp $Employee $EqualAccount $NetxvpAccount $Account]; $EqualAccount odb_commit; } ::set Notes [[$Employee ".notes"] odb_get]; ::append Notes [::string map "$Id~ $Id-" $Enotes]; [$Employee ".notes"] odb_set $Notes; $Employee odb_commit; ::return; } ::set Enotes ""; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_first [$TextLine ".employee"]; ::set Account [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds"] odb_factory]; ::set NetPayableAccount $Account; [$Account ".name"] odb_set "$Id=NETPAYABLE"; [$Account ".description"] odb_set "Net Wages Payable incl. Vacation Pay"; [$Account ".normal_balance"] odb_set "credit"; [$Account ".setup_column"] odb_set 1; [$Account ".employee"] odb_set [$Employee ".accounts"]; $Account odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$Account ".employee"] [$TextLine ".employee"]; ::append Enotes "\nCreated account name: [[$Account .name] odb_get]"; ::set PrevLine $Account; ::set Account [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds"] odb_factory]; ::set NetXvpAccount $Account; [$Account ".name"] odb_set "$Id=NETXVP"; [$Account ".description"] odb_set "Net Wages Payable excl. Vacation Pay"; [$Account ".normal_balance"] odb_set "credit"; [$Account ".setup_column"] odb_set 1; [$Account ".employee"] odb_set [$Employee ".accounts"]; ::if {$AW_totalto ne ""} { [$Account ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; } $Account odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$Account ".employee"] [$PrevLine ".employee"]; ::append Enotes "\nCreated account name: [[$Account .name] odb_get]"; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$Account ".employee"]; ::append Enotes "\nCreated text line description:"; ::set PrevLine $TextLine; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "WAGES PAYABLE"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$PrevLine ".employee"]; ::append Enotes "\nCreated text line description: WAGES PAYABLE"; ::set Account [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds"] odb_factory]; [$Account ".name"] odb_set "$Id=PAYABLE"; [$Account ".description"] odb_set "Total Wages Payable"; [$Account ".normal_balance"] odb_set "credit"; [$Account ".setup_column"] odb_set 1; [$Account ".employee"] odb_set [$Employee ".accounts"]; [$Account ".total.$Parent2"] odb_set [$NetPayableAccount ".total.kids"]; ::append Enotes "\nCreated account name: [[$Account .name] odb_get]"; ::append Enotes "\n[[$Account .name] odb_get] .total.$Parent2 set to [[$NetPayableAccount .name] odb_get]"; $Account odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$Account ".employee"] [$TextLine ".employee"]; ::set PrevLine $TextLine; ::foreach EqualAccount $EqualAccountList { ::set NetxvpAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id=NETXVP"]; ::append Enotes [employee_accounts_cleanup_accrual_position_and_totalto_xvp $Employee $EqualAccount $NetxvpAccount $Account]; $EqualAccount odb_commit; ::set PrevLine $EqualAccount; } ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$Account ".employee"]; ::append Enotes "\nCreated text line description:"; ::set PrevLine $TextLine; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "WAGES PAID"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$PrevLine ".employee"]; ::append Enotes "\nCreated text line description: WAGES PAID"; ::set GROSS_maybe ""; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-REG"]; ::if {$Reference ne ""} { ::set GROSS_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } ::if {$GROSS_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.REG"]; ::if {$Reference ne ""} { ::set GROSS_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$GROSS_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id~REG"]; ::if {$Reference ne ""} { ::set GROSS_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$GROSS_maybe eq ""} { ::set GROSS_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-GROSS"]; } ::if {$GROSS_maybe eq ""} { ::set GROSS_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.GROSS"]; } ::if {$GROSS_maybe ne ""} { ::set GROSS_maybe [$GROSS_maybe odb_master]; [$GROSS_maybe ".total.$Parent2"] odb_set [$NetPayableAccount ".total.kids"]; $GROSS_maybe odb_commit; ::append Enotes "\n[[$GROSS_maybe .name] odb_get] .total.$Parent2 set to [[$NetPayableAccount .name] odb_get]"; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$GROSS_maybe ".employee"]; ::append Enotes "\nCreated text line description:"; ::set PrevLine $TextLine; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "DEDUCTIONS"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$PrevLine ".employee"]; ::append Enotes "\nCreated text line description: DEDUCTIONS"; } ::set DEDUCT_maybe ""; ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-TAX"]; ::if {$Reference ne ""} { ::set DEDUCT_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } ::if {$DEDUCT_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.TAX"]; ::if {$Reference ne ""} { ::set DEDUCT_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$DEDUCT_maybe eq ""} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id~TAX"]; ::if {$Reference ne ""} { ::set DEDUCT_maybe [[[$Reference odb_master] ".total.parent1"] odb_get]; } } ::if {$DEDUCT_maybe eq ""} { ::set DEDUCT_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id-DEDUCT"]; } ::if {$DEDUCT_maybe eq ""} { ::set DEDUCT_maybe [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/TOTAL$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" "$Id.DEDUCT"]; } ::if {$DEDUCT_maybe ne ""} { ::set DEDUCT_maybe [$DEDUCT_maybe odb_master]; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_after [$TextLine ".employee"] [$DEDUCT_maybe ".employee"]; ::append Enotes "\nCreated text line description:"; } ::if {$AW_maybe ne ""} { ::set AW_maybe [$AW_maybe odb_master]; ::if {[[$AW_maybe ".employee"] odb_get] eq ""} { [$AW_maybe ".employee"] odb_set [$Employee ".accounts"]; $AW_maybe odb_commit; } } ::if {$AW_maybe ne ""} { ::set AW_maybe [$AW_maybe odb_master]; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_before [$TextLine ".employee"] [$AW_maybe ".employee"]; ::append Enotes "\nCreated text line description:"; ::set TextLine [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT.odb_deriveds"] odb_factory]; [$TextLine ".employee"] odb_set [$Employee ".accounts"]; [$TextLine ".folder"] odb_set "file"; [$TextLine ".line_type"] odb_set "text_line"; [$TextLine ".description"] odb_set "NV1 TIMECARDS & PAYMENTS"; $TextLine odb_commit; [$Employee ".accounts.index/interactive"] odb_make_before [$TextLine ".employee"] [$AW_maybe ".employee"]; ::append Enotes "\nCreated text line description: NV1 TIMECARDS & PAYMENTS"; } ::set Notes [[$Employee ".notes"] odb_get]; ::append Notes [::string map "$Id~ $Id-" $Enotes]; [$Employee ".notes"] odb_set $Notes; $Employee odb_commit; ::set Payroll [$_manager "/OBJECT/NEWVIEWS/PAYROLL/$_payrollCountry"]; ::set Notes [[$Payroll ".notes"] odb_get]; ::append Notes "\nEncountered Accrual Payroll Employee Id: $Id"; [$Payroll ".notes"] odb_set $Notes; $Payroll odb_commit; ::return; } method employee_accounts_cleanup_accrual_position_and_totalto_xvp {Employee EqualAccount AW_totalto PTaccount} { ::set Ofly $::qw::control(accrual_payroll_convert_on_the_fly); ::set Id [[$Employee ".employee_id"] odb_get]; ::set Dcount 100; ::set Parent1 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 0]; ::set Parent2 [::lindex $::qw::control(accrual_payroll_import_totalto_list) 1]; ::if {$AW_totalto ne ""} { } ::set Enotes ""; [$Employee ".accounts.index/interactive"] odb_make_before [$EqualAccount ".employee"] [[$PTaccount odb_master] ".employee"]; [$EqualAccount ".total.$Parent1"] odb_set [[$PTaccount odb_master] ".total.kids"]; ::append Enotes "\n[[$EqualAccount .name] odb_get] .total.$Parent1 set to [[[$PTaccount odb_master] .name] odb_get]"; ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { ::set TildaName [::string map "= ~" [[$EqualAccount ".name"] odb_get]]; ::set TildaAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $TildaName]; } else { ::set HyphenName [::string map "= -" [[$EqualAccount ".name"] odb_get]]; ;#// it's still has the tilda name! ::set HyphenAccount [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL/$_payrollCountry$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $HyphenName]; ::set TildaName $HyphenName; ::set TildaAccount $HyphenAccount; } ::if {$TildaAccount ne ""} { ::set TildaAccount [$TildaAccount odb_master]; ::if {[::sargs::get [[$TildaAccount ".paycodes"] odb_get] "/[$TildaAccount normal_balance_get].type"] eq "Vacation Pay Earned"} { ::set Eaccounts [[[$Employee ".accounts"] odb_primary] odb_masters]; ::foreach Eaccount $Eaccounts { ::if {[::string first "/OBJECT/NEWVIEWS/ACCOUNT/PAYROLL" [$Eaccount odb_path]]!=0} { ::continue; } ::switch -exact -- [$Eaccount normal_balance_get] { "debit" { } "credit" { ::if {[::sargs::get [[$Eaccount ".paycodes"] odb_get] "/credit.type"] eq "Vacation Pay Withheld"} { ::set AW_totalto [[$Eaccount ".total.parent2"] odb_get]; ::break; } } } } } } ::if {$AW_totalto ne ""} { ::if {[[$EqualAccount ".total.parent2"] odb_get] eq ""} { [$EqualAccount ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; ::append Enotes "\n[[$EqualAccount .name] odb_get] .total.$Parent2 set to [[[$AW_totalto odb_master] .name] odb_get]"; } } ::if {$TildaAccount ne ""} { ::set TildaAccount [$TildaAccount odb_master]; ::set Report [[$TildaAccount ".report"] odb_get]; ::if {$Report ne ""} { [[$Report odb_master] ".accounts.index/interactive"] odb_make_before [$EqualAccount ".report"] [$TildaAccount ".report"]; } ::if {$AW_totalto ne ""} { ::set Tap2 [[$TildaAccount ".total.parent2"] odb_get]; ::if {$Tap2 eq ""} { [$TildaAccount ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; ::append Enotes "\n[[$TildaAccount .name] odb_get] .total.$Parent2 set to [[[$AW_totalto odb_master] .name] odb_get]"; } else { ::append Enotes "\n*** WARNING *** [[$TildaAccount .name] odb_get] .total.$Parent2 is already set to [[[$Tap2 odb_master] .name] odb_get]"; ::if {$::qw::control(accrual_payroll_convert_on_the_fly)} { [$TildaAccount ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; ::append Enotes "\n\t[[$TildaAccount .name] odb_get] .total.$Parent2 set to [[[$AW_totalto odb_master] .name] odb_get]"; [$TildaAccount ".total.parent3"] odb_set $Tap2; ::append Enotes "\n\t[[$TildaAccount .name] odb_get] .total.parent3 set to [[[$Tap2 odb_master] .name] odb_get]"; } else { ::if {$Tap2 ne [[$AW_totalto odb_master] ".total.kids"]} { [$TildaAccount ".total.$Parent2"] odb_set [[$AW_totalto odb_master] ".total.kids"]; ::append Enotes "\n\t[[$TildaAccount .name] odb_get] .total.$Parent2 set to [[[$AW_totalto odb_master] .name] odb_get]"; [$TildaAccount ".total.parent3"] odb_set $Tap2; ::append Enotes "\n\t[[$TildaAccount .name] odb_get] .total.parent3 set to [[[$Tap2 odb_master] .name] odb_get]"; } } } $TildaAccount odb_commit; } } ::return $Enotes; } method is_employee_active {Employee} { ::set EmployeeId [[$Employee ".employee_id"] odb_get]; ::if {$_payrollCountry eq "CANADA"} { ::if {[[$Employee ".termination_code"] odb_get] ne ""} { ::append _payroll_convert_notes "* Employee $EmployeeId set to Inactive (Termination code found)\n"; ::return 0; } } ::if {[[$Employee ".last_day_worked"] odb_get] ne ""} { ::append _payroll_convert_notes "* Employee $EmployeeId set to Inactive (Last day worked was found)\n"; ::return 0; } ::if {[[$Employee ".paychecks"] odb_items]==0} { ::append _payroll_convert_notes "* Employee $EmployeeId set to Inactive (No paychecks found)\n"; ::return 0; } ::set LastCheckDate [[[[[$Employee ".paychecks.index/date"] odb_last] odb_master] ".date"] odb_get]; ::if {[::qw::date::difference $_current_fiscal_year_end $LastCheckDate "year"]>1} { ::append _payroll_convert_notes "* Employee $EmployeeId set to Inactive (Last paycheck more than one year ago)\n"; ::return 0; } ::return 1; } method employee_government_totals_accounts_destroy {Employee Import_Datum} { ::set GT_Accounts [::sargs::get $Import_Datum ".gt_accounts"]; ::if {$GT_Accounts eq ""} {::return $Import_Datum;} ::foreach Sub [::sargs::subs .structure $GT_Accounts] { ::if {$Sub eq "/AW"} {::continue;} ::set AccountName [::sargs::get $GT_Accounts $Sub]; ::if {![accountExists $AccountName]} { status "Remove GT account $AccountName failed, account does not exist."; ::continue; } ::set Account [account_get $AccountName]; ::if {[[$Account ".postings"] odb_items]!=0} { ::append _payroll_convert_notes "* Employee [[$Employee .employee_id] odb_get], cannot remove GT account $AccountName, account contains [[$Account .postings] odb_items] postings.\n"; status "Remove GT account $AccountName failed, account contains [[$Account .postings] odb_items] postings."; ::continue; } ::append _payroll_convert_notes "Employee [[$Employee .employee_id] odb_get], GT account $AccountName deleted.\n"; status "Removing employee GT account $AccountName"; $Account odb_destroy; ::set GT_Accounts [::sargs::unset $GT_Accounts $Sub]; ::if {$_commit_sequence>=$_commit_limit} { $_manager cpp_commit; ::set _commit_sequence 0; } } ::if {[::llength [::sargs::subs .structure $GT_Accounts]]} { ::sargs::var::set Import_Datum ".gt_accounts" $GT_Accounts; } else { ::set Import_Datum [::sargs::unset $Import_Datum ".gt_accounts"]; } ::return $Import_Datum; } method account_get_if_exists {Name} { ::set Name [stringFilter $Name]; ::if {![::info exists _account_class_array($Name)]} {::return "";} ::set Class $_account_class_array($Name); ::if {$Class eq "PAYROLL"} {::set Class "PAYROLL/${_payrollCountry}";} ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/$Class$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Name]; ::if {$Reference eq ""} {::return "";} ::return [$Reference odb_master]; } method employee_benefits_accounts_destroy {Employee Import_Datum} { ::set Benefits_Info [::sargs::get $Import_Datum ".benefits"]; ::foreach Sub [::sargs::subs .structure $Benefits_Info] { ::set Benefit [::sargs::get $Benefits_Info $Sub]; ::foreach Sign {debit credit} { ::set AccountName [::sargs::get $Benefit ".account/$Sign"]; status "Removing employee benefit account $AccountName"; ::set Account [account_get_if_exists $AccountName]; ::if {$Account eq ""} { import_error "Could not delete employee benefit acount $AccountName, the account does not exist"; } else { ::if {[[$Account ".postings"] odb_items]!=0} { ::append _payroll_convert_notes "* Employee [[$Employee .employee_id] odb_get], cannot remove benefit account $AccountName, account contains [[$Account .postings] odb_items] postings.\n"; status "Remove benefit account $AccountName failed, account contains [[$Account .postings] odb_items] postings."; ::set PayCodes [[$Account ".paycodes"] odb_get]; ::sargs::var::set PayCodes "/debit.quantity" "" "/debit.rate" "" "/debit.percent" "" "/credit.quantity" "" "/credit.rate" "" "/credit.percent" ""; [$Account ".paycodes"] odb_set $PayCodes; [$Account ".active"] odb_set "inactive"; $Account odb_commit; ::continue; } $Account odb_destroy; ::append _payroll_convert_notes "Employee [[$Employee .employee_id] odb_get] benefit account $AccountName deleted.\n"; ::set Benefit [::sargs::unset $Benefit ".account/$Sign"]; } } ::sargs::var::set Benefits_Info $Sub $Benefit; } ::sargs::var::set Import_Datum ".benefits" $Benefits_Info; ::return $Import_Datum; } method isInteger {Src} { ::return [::regexp -- {^-?[0-9]+$} $Src]; } method isDouble {Src} { ::if {$Src eq "."} {::return 0;} ::return [::regexp -- {^-?[0-9]*\.?[0-9]*$} $Src]; } method largeAdd {Src1 Src2} { ::set Carry 0; ::set Result ""; ::while {1} { ::set Op1 [::string range $Src1 end end]; ::set Op2 [::string range $Src2 end end]; ::if {$Op1==""&&$Op2==""} {::break;} ::set Src1 [::string range $Src1 0 end-1]; ::set Src2 [::string range $Src2 0 end-1]; ::set Sum [::expr $Op1+$Op2+$Carry]; ::if {$Sum>9} {::incr Sum -10;::set Carry 1;} else {::set Carry 0;} ::set Result "$Sum$Result"; } ::if {$Carry} {::return "$Carry$Result";} ::return $Result; } method is_valid_nv1_date {Src} { ::if {[::string length $Src]!=8} {::return 0;} ::if {![::string is digit $Src]} {::return 0;} ::set NV2Date [::string range $Src 4 7][::string range $Src 2 3][::string range $Src 0 1]; ::qw::try { ::qw::date::check $NV2Date; } catch Exception { ::return 0; } ::return 1; } method nv1_keystroke_to_ymdhms {Src} { ::qw::try { ::if {$Src eq ""||$Src==0} {::return 19030101;} ::if {[::string length $Src]!=8} {import_error "The date should have eight characters.";} ::if {![::string is digit $Src]} {import_error "Non-digit characters encountered.";} ::return [::string range $Src 4 7][::string range $Src 2 3][::string range $Src 0 1]; } catch Exception { import_error "Could not convert \"$Src\" from NewViews 1 keystroke format to YYYYMMDDHHMMSS format." $Exception; } } method procedureExists {Procedure} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Procedure]; ::if {$Reference ne ""} {::return 1;} ::return 0; } public method procedureRecords {Src} { ::set Name $Src; ::if {![procedureExists $Name]} {import_error "Procedure $Src does not exist.";} ::set Reference [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Src]; ::return [[[$Reference odb_master] .records] odb_get]; } public method procedureNotes {Src} { ::set Name $Src; ::if {![procedureExists $Name]} {import_error "Procedure $Src does not exist.";} ::set Reference [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Src]; ::return [[[$Reference odb_master] .notes] odb_get]; } public method procedureSource {Src} { ::set Name $Src; ::if {![procedureExists $Name]} {import_error "Procedure $Src does not exist.";} ::set Reference [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/DOS/PROCEDURE$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Src]; ::return [[[$Reference odb_master] .source] odb_get]; } method accountExists {Src} { ::set Src [stringFilter $Src]; ::if {![::info exists _account_class_array($Src)]} {::return 0;} ::set Class $_account_class_array($Src); ::if {$Class eq "PAYROLL"} {::set Class "PAYROLL/$_payrollCountry";} ::set Reference [[$_manager "/OBJECT/NEWVIEWS/ACCOUNT/$Class$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Src]; ::if {$Reference ne ""} {::return 1;} ::return 0; } method reportExists {Report} { ::set Reference [[$_manager "/OBJECT/NEWVIEWS/REPORT$_slashIdPrefix.odb_deriveds.index/name"] odb_find_key ".name" $Report]; ::if {$Reference!=""} {::return 1;} ::return 0; } public method padRight {Src Length Char} { ::if {[::string length $Src]==$Length} {::return $Src;} ::if {[::string length $Src]<$Length} {::return $Src[::string repeat $Char [::expr $Length - [::string length $Src]]]} ::return [::string range $Src 0 [::expr $Length - 1]] } public method puts_pgq {Arg} { ::return ""; ::uplevel 1 ::puts $Arg; } public method puts_rth {Arg} { ::return ""; ::puts "20070503_001 Arg==$Arg"; } public method signal_receive {s_args} { ::switch -- [::sargs::get $s_args .tag] { "manager" { ::switch -- [::sargs::get $s_args .command] { odb_commit_before { if {$_is_importing} { import_error "The NewViews legacy data importer is currently running."; } return; } odb_abort_before { if {$_is_importing} { import_error "The NewViews legacy data importer is currently running."; } return; } cpp_destroy_after { ::qw::itcl_delete_object $this; } } } } return ""; } public method employee_count {Arg} { increment "employees-target"; } public method employee_process {Arg} { ::qw::throw [::sargs \ .text "Called deprecated method employee_process" \ .help_id 0 \ ]; ::set EmployeeId [::sargs::get $Arg ".employee_id"]; ::if {$EmployeeId eq ""} {import_error "No .employee_id found in employee.";} ::if {![::sargs::exists $Arg ".country"]} {import_error "No .country found in employee $EmployeeId."} ::set Country [::sargs::get $Arg ".country"]; ::set EmployeeName "[::sargs::get $Arg .employee_name.last], [::sargs::get $Arg .employee_name.first]"; ::set EmployeeId [makeEmployeeIdUnique $EmployeeId]; status "Employee: $EmployeeName"; ::set Employee [[$_manager "/OBJECT/NEWVIEWS/SYSTEM/EMPLOYEE/${Country}.odb_deriveds"] odb_factory]; [$Employee ".folder"] odb_set "file"; [$Employee ".employee_id"] odb_set $EmployeeId; ::set Payroll [[[$_manager "/OBJECT/NEWVIEWS/PAYROLL/${Country}.odb_deriveds.index/name"] odb_find_key ".name" "EMPLOYEES"] odb_master]; [$Employee ".payroll"] odb_set [$Payroll ".employees"]; ::foreach Field {".date_of_birth" ".first_day_worked" ".last_day_worked" ".raise_due_date" ".review_due_date"} { ::if {[::sargs::exists $Arg $Field]} { ::set Date [nv1_keystroke_to_ymdhms [::sargs::get $Arg $Field]]; ::if {$Date ne ""} { ::set Date [validate "date" $Date]; [$Employee $Field] odb_set $Date; } } } ::if {$Country eq "CANADA" && [::sargs::exists $Arg ".social_insurance_number"]} { ::set Number [::sargs::get $Arg ".social_insurance_number"]; ::if {[[$Employee ".social_insurance_number"] isValid $Number]} { [$Employee ".social_insurance_number"] odb_set $Number; } } ::if {$Country eq "USA" && [::sargs::exists $Arg ".social_security_number"]} { ::set Number [::sargs::get $Arg ".social_security_number"]; [$Employee ".social_security_number"] odb_set $Number; } ::if {[::sargs::exists $Arg ".sex"]} { ::set Sex [validate ".sex" [::sargs::get $Arg ".sex"]]; ::if {$Sex ne ""} { [$Employee ".sex"] odb_set $Sex; } } ::foreach Field { ".employee_name.salutation" ".employee_name.first" ".employee_name.middle" ".employee_name.last" ".employee_name.print_as" ".address.freeform" ".address.street" ".address.street2" ".address.city" ".address.state" ".address.country" ".address.zipcode" ".address.phone.freeform" ".address.phone.country_code" ".address.phone.area_code" ".address.phone.prefix" ".address.phone.suffix" ".address.phone.extension" ".address.phone/fax.freeform" ".address.phone/fax.country_code" ".address.phone/fax.area_code" ".address.phone/fax.prefix" ".address.phone/fax.suffix" ".address.phone/fax.extension" ".address.phone/cell.freeform" ".address.phone/cell.country_code" ".address.phone/cell.area_code" ".address.phone/cell.prefix" ".address.phone/cell.suffix" ".address.phone/cell.extension" ".address.phone/emergency.freeform" ".address.phone/emergency.country_code" ".address.phone/emergency.area_code" ".address.phone/emergency.prefix" ".address.phone/emergency.suffix" ".address.phone/emergency.extension" ".emergency_contact" ".address.email" ".address.website" ".marital_status" ".occupation" ".department" ".union_classification" ".starting_wage" ".other_information" } { ::if {[::sargs::exists $Arg $Field]} { ::set Value [::sargs::get $Arg $Field]; ::if {$Value ne ""} { [$Employee $Field] odb_set $Value; } } } ::if {$Country eq "CANADA"} { ::foreach Field { ".province_of_employment" ".federal.td1_claim_amount" ".federal.td1_additional_tax" ".federal.td1_prescribed_zone_deduction" ".federal.tax_exempt" ".federal.cpp_exempt" ".federal.ei_exempt" ".federal.other_tax_credits" ".federal.additional_exemption" ".federal.lsf_purchase_amount" ".federal.manual_tax_calculation" ".federal.td1x_estimated_income" ".provincial.td1_claim_amount" ".provincial.tax_exempt" ".provincial.td1_y_factor" ".provincial.other_tax_credits" ".provincial.lsf_purchase_amount" ".provincial.manual_tax_calculation" ".quebec.claim_amount" ".quebec.tax_exempt" ".quebec.additional_tax" ".quebec.additional_deduction" ".quebec.manual_tax_calculation" ".non_cash_taxable_benefits/1.amount" ".non_cash_taxable_benefits/1.amount_period" ".non_cash_taxable_benefits/1.percent" ".non_cash_taxable_benefits/1.percentage_base" ".non_cash_taxable_benefits/1.description" ".non_cash_taxable_benefits/1.t4_box" ".non_cash_taxable_benefits/1.releve1_box" ".non_cash_taxable_benefits/1.taxable" ".non_cash_taxable_benefits/1.quebec_taxable" ".non_cash_taxable_benefits/1.insurable" ".non_cash_taxable_benefits/1.pensionable" ".non_cash_taxable_benefits/1.vacationable" ".non_cash_taxable_benefits/2.amount" ".non_cash_taxable_benefits/2.amount_period" ".non_cash_taxable_benefits/2.percent" ".non_cash_taxable_benefits/2.percentage_base" ".non_cash_taxable_benefits/2.description" ".non_cash_taxable_benefits/2.t4_box" ".non_cash_taxable_benefits/2.releve1_box" ".non_cash_taxable_benefits/2.taxable" ".non_cash_taxable_benefits/2.quebec_taxable" ".non_cash_taxable_benefits/2.insurable" ".non_cash_taxable_benefits/2.pensionable" ".non_cash_taxable_benefits/2.vacationable" ".non_cash_taxable_benefits/3.amount" ".non_cash_taxable_benefits/3.amount_period" ".non_cash_taxable_benefits/3.percent" ".non_cash_taxable_benefits/3.percentage_base" ".non_cash_taxable_benefits/3.description" ".non_cash_taxable_benefits/3.t4_box" ".non_cash_taxable_benefits/3.releve1_box" ".non_cash_taxable_benefits/3.taxable" ".non_cash_taxable_benefits/3.quebec_taxable" ".non_cash_taxable_benefits/3.insurable" ".non_cash_taxable_benefits/3.pensionable" ".non_cash_taxable_benefits/3.vacationable" ".non_cash_taxable_benefits/4.amount" ".non_cash_taxable_benefits/4.amount_period" ".non_cash_taxable_benefits/4.percent" ".non_cash_taxable_benefits/4.percentage_base" ".non_cash_taxable_benefits/4.description" ".non_cash_taxable_benefits/4.t4_box" ".non_cash_taxable_benefits/4.releve1_box" ".non_cash_taxable_benefits/4.taxable" ".non_cash_taxable_benefits/4.quebec_taxable" ".non_cash_taxable_benefits/4.insurable" ".non_cash_taxable_benefits/4.pensionable" ".non_cash_taxable_benefits/4.vacationable" ".termination_code" ".termination_comments/1.text" ".termination_comments/2.text" ".termination_comments/3.text" ".termination_comments/4.text" ".termination_comments/5.text" } { ::if {[::sargs::exists $Arg $Field]} { ::set Value [::sargs::get $Arg $Field]; ::if {$Value ne ""} { [$Employee $Field] odb_set $Value; } } } } $Employee odb_commit; increment "employees-processed"; } }