@@ -76,6 +76,28 @@ The C<_book_todo> context parameter is modified to include the result.
7676
7777=item * approve
7878
79+ =item * calculate_totals
80+
81+ Calculates a slew of summarized values for the reconciliation.
82+
83+ =over 8
84+
85+ =item * _cleared_debits, _cleared_credits, _cleared_total, _cleared_balance
86+
87+ =item * _uncleared_debits, _uncleared_credits, _uncleared_total
88+
89+ =item * _mismatch_debits, _mismatch_credits, _mismatch_total
90+
91+ =item * _total_ledger_debits, _total_ledger_credits
92+
93+ =item * _total_stmt_debits, _total_stmt_credits
94+
95+ B<TODO >
96+
97+ =item * _gl_ending_balance
98+
99+ =back
100+
79101=item * delete
80102
81103=item * reconcile
@@ -137,6 +159,9 @@ sub execute($self, $wf) {
137159 elsif ($self -> entrypoint eq ' reject' ) {
138160 $self -> _reject( $wf );
139161 }
162+ elsif ($self -> entrypoint eq ' calculate_totals' ) {
163+ $self -> _calculate_totals( $wf );
164+ }
140165}
141166
142167# ####################################
@@ -405,6 +430,72 @@ sub _submit($self, $wf) {
405430 $wf -> context-> param( ' submitted' , 1 );
406431}
407432
433+ # ####################################
434+ #
435+ # calculate_totals
436+ #
437+ # ####################################
438+
439+ sub _calculate_totals ($self , $wf ) {
440+ my $ctx = $wf -> context;
441+ my $book_todo = $ctx -> param( ' _book_todo' );
442+ my $stmt_todo = $ctx -> param( ' _stmt_todo' );
443+ my $recon_done = $ctx -> param( ' _recon_done' );
444+
445+ my $credits = LedgerSMB::PGNumber-> bzero;
446+ my $debits = LedgerSMB::PGNumber-> bzero;
447+ my $total = LedgerSMB::PGNumber-> bzero;
448+ for my $line (map { $_ -> {book } } $recon_done -> @*) {
449+ $credits += $line -> {our_credits };
450+ $debits += $line -> {our_debits };
451+ $total += $line -> {our_balance };
452+ }
453+ my $cleared_balance = $ctx -> param( ' _starting_cleared_balance' )
454+ + $ctx -> param( ' _cleared_total' );
455+ $ctx -> param( ' _cleared_credits' , $credits );
456+ $ctx -> param( ' _cleared_debits' , $debits );
457+ $ctx -> param( ' _cleared_total' , $total );
458+ $ctx -> param( ' _cleared_balance' , $cleared_balance );
459+
460+ $credits = LedgerSMB::PGNumber-> bzero;
461+ $debits = LedgerSMB::PGNumber-> bzero;
462+ $total = LedgerSMB::PGNumber-> bzero;
463+ for my $line ($book_todo -> @*) {
464+ $credits += $line -> {our_credits };
465+ $debits += $line -> {our_debits };
466+ $total += $line -> {our_balance };
467+ }
468+ $ctx -> param( ' _uncleared_credits' , $credits );
469+ $ctx -> param( ' _uncleared_debits' , $debits );
470+ $ctx -> param( ' _uncleared_total' , $total );
471+
472+ $credits = LedgerSMB::PGNumber-> bzero;
473+ $debits = LedgerSMB::PGNumber-> bzero;
474+ $total = LedgerSMB::PGNumber-> bzero;
475+ for my $line ($stmt_todo -> @*) {
476+ $credits += $line -> {our_credits };
477+ $debits += $line -> {our_debits };
478+ $total += $line -> {our_balance };
479+ }
480+ $ctx -> param( ' _mismatch_credits' , $credits );
481+ $ctx -> param( ' _mismatch_debits' , $debits );
482+ $ctx -> param( ' _mismatch_total' , $total );
483+
484+ my $total_book_credits =
485+ $ctx -> param( ' _cleared_credits' ) + $ctx -> param( ' _uncleared_credits' );
486+ my $total_book_debits =
487+ $ctx -> param( ' _cleared_debits' ) + $ctx -> param( ' _uncleared_debits' );
488+ $ctx -> param( ' _total_ledger_credits' , $total_book_credits );
489+ $ctx -> param( ' _total_ledger_debits' , $total_book_debits );
490+
491+ my $gl_ending_balance =
492+ $ctx -> param( ' _starting_cleared_balance' )
493+ + $ctx -> param( ' _cleared_total' )
494+ + $ctx -> param( ' _uncleared_total' );
495+ $ctx -> param( ' _gl_ending_balance' , $gl_ending_balance );
496+ }
497+
498+
4084991;
409500
410501=head1 LICENSE AND COPYRIGHT
0 commit comments