/* { This is a good place for general newviews utilitiy functionality that doesn't really belong as a method in any newviews class. Perhaps it could belong to a class as a static (common) method but let's not quibble. */ } ::namespace eval ::qw::nv2util {} ::proc ::qw::nv2util::transaction_is_boomerang {sargs} { /* { Usage: ::set IsBoomerang [::qw::nv2util::transaction_is_boomerang .database $Database .address TransactionAddress]; ::set IsBoomerang [::qw::nv2util::transaction_is_boomerang .database $Database .object_id TransactionObjectId]; ::set IsBoomerang [::qw::nv2util::transaction_is_boomerang .database $Database .object_structure TransactionOS]; A transaction is a boomerang iff the qw_get of the .posting/debit.account and the .posting/credit.account are both non-empty and point to the same account. */ } ::set Database [::sargs::get $sargs .database]; ::if {$Database eq ""} { ::qw::bug 314120171006143056 "[::qw::procname] - no database."; } ::set OS [::sargs::get $sargs .object_structure]; ::if {[::sargs::size $OS]==0} { ::set OS [$Database cpp_object_structure_find $sargs]; } ::if {[::sargs::size $OS]==0} { ::qw::bug 314120171006143057 "[::qw::procname] - no transaction."; } ::set DebitSideAccount [::sargs::get $OS .data.posting/debit.account]; ::if {$DebitSideAccount eq ""} { ::return 0; } ::set CreditSideAccount [::sargs::get $OS .data.posting/credit.account]; ::if {$CreditSideAccount eq ""} { ::return 0; } ::if {$DebitSideAccount eq $CreditSideAccount} { ::return 1; } ::return 0; } ::proc ::qw::nv2util::find_journal_by_name {sargs} { /* { Parses a journal name. Checks that it exists and is unique. Returns its odb_address or else throws an exception. Usage: ::set JournalAddress [::qw::nv2util::find_journal_by_name \ .journal_name BALANCE_FORWARD \ .journal description "balance forward journal" \ .database $Database \ ]; */ } ::set Database [::sargs::get $sargs .database]; ::if {![::qw::command_exists $Database]} { ::qw::bug 314120171011104814 "[::qw::procname] - no .database argument."; } ::set JournalName [::sargs::get $sargs .journal_name]; ::set JournalName [::string trim $JournalName]; ::set JournalName [::string tolower $JournalName]; ::if {$JournalName eq ""} { ::qw::bug 314120171011104815 "[::qw::procname] - no .journal_name argument."; } ::set JournalDescription [::sargs::get $sargs .journal_description]; ::if {$JournalDescription eq ""} { ::set JournalDescription "journal"; } ::switch -- [::llength [::split $JournalName /]] { 0 { ::qw::throw \ .text "The balance forward journal must be specified." \ ; } 1 { /* { We were given a name. Use the name closure of the root journal. */ } ::set OS [$Database cpp_object_structure_load .path /OBJECT/NEWVIEWS/JOURNAL]; ::set ObjectId [::sargs::get $OS .system.object_id]; ::set ClassPath [::sargs::get $OS .system.class_path]; ::set MasterList [$Database cpp_file_odb_masters \ .path /odb/index$ClassPath.odb_deriveds.index/name_closure \ .range.begin [::list string $ObjectId string $JournalName] \ .range.end [::list string $ObjectId string $JournalName] \ .order_is_kept 1 \ ]; ::set MasterList1 [::list]; ::foreach Master $MasterList { ::set OS [$Database cpp_object_structure_load .address $Master]; ::if {[::string tolower $JournalName] eq [::string tolower [::sargs::get $OS .data.name]]} { ::lappend MasterList1 $Master; } } ::set MasterList $MasterList1; ::switch -- [::llength $MasterList] { 0 { ::qw::throw \ .text "Couldn't find a journal with name \"$JournalName\"." \ .error_id 314120140609100656 \ .help_page [::subst -nocommands { .id 314120140609100656 .tags {error} .journal_name $JournalName \ .body { [p { There was no $JournalDescription with the name [qw_quoted [qw_field_value [qw_s_args .journal_name]]]. Enter an $JournalDescription with a different name. }] } }] \ ; } 1 { ::set Journal [::lindex $MasterList 0]; } default { ::set PathList [::list]; ::foreach Master $MasterList { ::lappend PathList [$Master odb_path_help]; } ::set Length [::llength $MasterList]; ::qw::throw \ .text "$Length journals have the name \"$JournalName\"." \ .error_id 314120140609100657 \ .help_page [::subst -nocommands { .id 314120140609100657 .tags {error} .body { [p { $Length journals matched the name entered for the $JournalDescription. They are $PathList. }] [p { Because of the conflict it is not sufficient to enter just the journal name. You must enter the path to the desired journal, such as /OBJECT/NEWVIEWS/JOURNAL/GENERAL/ABC, or it can be shortened to /JOURNAL/GENERAL/ABC. }] } }] \ ; } } } default { /* { We were given a path. Use that path. */ } ::if {[::string first "/journal" $JournalName]==0} { ::set JournalName "/object/newviews$JournalName"; } ::if {[::string first "/object/newviews/journal" $JournalName]!=0} { /* { 2.28.4 - added this check to avoid a bug being thrown. If the path didn't begin with /object then cpp_object_structure_find threw a bug. */ } ::qw::throw \ .text "The journal path must start with \"/object/newviews/journal\" or just \"/journal\"." \ .error_id 314120160328165130 \ .help_page [::subst -nocommands { .id 314120160328165130 .tags {error} .body { [p { You can specify either the journal's name or the path to the journal. If you specify the name then NewViews will search all journals for just the one that has that name and report an error if more than one is found. But if you specify a path, then the path to the journal can be specified as the full path such as [qw_directory /object/newviews/journal/general/abc], or shortened to just [qw_directory /journal/general/abc]. }] [p { Note it doesn't matter if you use upper or lower case. }] } }] \ ; } ::set OS [$Database cpp_object_structure_find .path $JournalName]; ::if {[::sargs::size $OS]==0} { ::qw::throw \ .text "Couldn't find a journal from path \"$JournalName\"." \ ; } ::set ObjectId [::sargs::get $OS .system.object_id]; ::set Journal [::qw::odb::address_from_disk .object_id $ObjectId .database $Database]; } } ::set JournalPath [$Journal odb_path]; ::switch -glob -- $JournalPath { /OBJECT/NEWVIEWS/JOURNAL/GENERAL/* { #*/ } /OBJECT/NEWVIEWS/JOURNAL/BANK/* { #*/ /* { rwb is using the bank payment journal. */ } ::if {![::string match -nocase benn* [::info hostname]]} { ::qw::throw \ .text "The $JournalDescription must be a general journal." \ ; } } default { ::qw::throw \ .text "The $JournalDescription must be a general journal." \ ; } } ::if {[$Journal odb_is_class]} { ::qw::throw [::subst -nocommands { .text "Journal $JournalPath is a class." \ .help_page { .id 314120141002105525 .tags {error} .body { [p { $JournalPath is a journal class. You must specify a leaf journal; a journal that you can add transactions to. }] } } }]; } ::set KidCount [[$Journal .odb_deriveds] odb_items]; ::if {$KidCount!=0} { ::qw::throw [::subst -nocommands { .text "Journal $JournalPath is a branch journal." \ .help_page { .id 314120141002105527 .tags {error} .body { [p { $JournalPath is a branch journal with $KidCount sub-journals. You must specify a leaf journal, i.e. a journal that you can add transactions to. }] } } }]; } ::return $Journal; }