moved mbts builder to apputils to share, circ code now uses the mbts instead of open_...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 24 Oct 2006 20:22:08 +0000 (20:22 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 24 Oct 2006 20:22:08 +0000 (20:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6504 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Money.pm

index f1c4c80..ca0e3d5 100644 (file)
@@ -1977,6 +1977,7 @@ sub _user_transaction_history {
 }
 =cut
 
+=head SEE APPUTILS.PM
 sub _make_mbts {
        my @xacts = @_;
 
@@ -2029,6 +2030,7 @@ sub _make_mbts {
 
        return @mbts;
 }
+=cut
 
 sub user_transaction_history {
        my( $self, $conn, $auth, $userid, $type ) = @_;
@@ -2052,7 +2054,8 @@ sub user_transaction_history {
 
        $e->rollback;
 
-       my @mbts = _make_mbts( @xacts );
+       #my @mbts = _make_mbts( @xacts );
+       my @mbts = $U->make_mbts( @xacts );
 
        if(defined($type)) {
                @mbts = grep { $_->xact_type eq $type } @mbts;
index da2a573..3685452 100644 (file)
@@ -1123,5 +1123,97 @@ sub patron_total_items_out {
 }
 
 
+
+
+#---------------------------------------------------------------------
+# Returns  ($summary, $event) 
+#---------------------------------------------------------------------
+sub fetch_mbts {
+       my $self = shift;
+       my $id  = shift;
+       my $editor = shift || new_editor();
+
+       $id = $id->id if (ref($id));
+
+       my $xact = $editor->retrieve_money_billable_transaction(
+               [
+                       $id, {  
+                               flesh => 1, 
+                               flesh_fields => { mbt => [ qw/billings payments grocery circulation/ ] } 
+                       }
+               ]
+       ) or return (undef, $editor->event);
+
+       return $self->make_mbts($xact);
+}
+
+
+#---------------------------------------------------------------------
+# Given a list of money.billable_transaction objects, this creates
+# transaction summary objects for each
+#--------------------------------------------------------------------
+sub make_mbts {
+       my $self = shift;
+       my @xacts = @_;
+
+       my @mbts;
+       for my $x (@xacts) {
+
+               my $s = new Fieldmapper::money::billable_transaction_summary;
+
+               $s->id( $x->id );
+               $s->usr( $x->usr );
+               $s->xact_start( $x->xact_start );
+               $s->xact_finish( $x->xact_finish );
+               
+               my $to = 0;
+               my $lb = undef;
+               for my $b (@{ $x->billings }) {
+                       next if ($self->is_true($b->voided));
+                       $to += ($b->amount * 100);
+                       $lb ||= $b->billing_ts;
+                       if ($b->billing_ts ge $lb) {
+                               $lb = $b->billing_ts;
+                               $s->last_billing_note($b->note);
+                               $s->last_billing_ts($b->billing_ts);
+                               $s->last_billing_type($b->billing_type);
+                       }
+               }
+
+               $s->total_owed( sprintf('%0.2f', $to / 100 ) );
+               
+               my $tp = 0;
+               my $lp = undef;
+               for my $p (@{ $x->payments }) {
+                       next if ($self->is_true($p->voided));
+                       $tp += ($p->amount * 100);
+                       $lp ||= $p->payment_ts;
+                       if ($p->payment_ts ge $lp) {
+                               $lp = $p->payment_ts;
+                               $s->last_payment_note($p->note);
+                               $s->last_payment_ts($p->payment_ts);
+                               $s->last_payment_type($p->payment_type);
+                       }
+               }
+
+               $s->total_paid( sprintf('%0.2f', $tp / 100 ) );
+               $s->balance_owed( sprintf('%0.2f', ($to - $tp) / 100) );
+               $s->xact_type( 'grocery' ) if ($x->grocery);
+               $s->xact_type( 'circulation' ) if ($x->circulation);
+
+               $logger->debug("Created mbts with balance_owed = ". $s->balance_owed);
+               
+               push @mbts, $s;
+       }
+               
+       return @mbts;
+}
+               
+               
+               
+               
+               
+                       
+       
 1;
 
index 5e27a84..54e8d12 100644 (file)
@@ -1674,9 +1674,11 @@ sub checkin_handle_circ {
    }
 
    # see if there are any fines owed on this circ.  if not, close it
-       $obt = $self->editor->retrieve_money_open_billable_transaction_summary($circ->id);
+       ($obt) = $U->fetch_mbts($circ->id, $self->editor);
    $circ->xact_finish('now') if( $obt and $obt->balance_owed == 0 );
 
+       $logger->debug("circulator: ".$obt->balance_owed." is owed on this circulation");
+
    # Set the checkin vars since we have the item
    $circ->checkin_time('now');
    $circ->checkin_staff($self->editor->requestor->id);
index ce2689a..eb9fdd3 100644 (file)
@@ -489,91 +489,28 @@ sub _check_open_xact {
 }
 
 
-sub _make_mbts {
-        my @xacts = @_;
-
-        my @mbts;
-        for my $x (@xacts) {
-                my $s = new Fieldmapper::money::billable_transaction_summary;
-                $s->id( $x->id );
-                $s->usr( $x->usr );
-                $s->xact_start( $x->xact_start );
-                $s->xact_finish( $x->xact_finish );
-
-                my $to = 0;
-                my $lb = undef;
-                for my $b (@{ $x->billings }) {
-                       next if ($U->is_true($b->voided));
-                        $to += ($b->amount * 100);
-                        $lb ||= $b->billing_ts;
-                        if ($b->billing_ts ge $lb) {
-                                $lb = $b->billing_ts;
-                                $s->last_billing_note($b->note);
-                                $s->last_billing_ts($b->billing_ts);
-                                $s->last_billing_type($b->billing_type);
-                        }
-                }
-               $s->total_owed( sprintf('%0.2f', $to / 100 ) );
-
-                my $tp = 0;
-                my $lp = undef;
-                for my $p (@{ $x->payments }) {
-                       next if ($U->is_true($p->voided));
-                        $tp += ($p->amount * 100);
-                        $lp ||= $p->payment_ts;
-                        if ($p->payment_ts ge $lp) {
-                                $lp = $p->payment_ts;
-                                $s->last_payment_note($p->note);
-                                $s->last_payment_ts($p->payment_ts);
-                                $s->last_payment_type($p->payment_type);
-                        }
-                }
-               $s->total_paid( sprintf('%0.2f', $tp / 100 ) );
-
-               $s->balance_owed( sprintf('%0.2f', ($to - $tp) / 100) );
-
-                $s->xact_type( 'grocery' ) if ($x->grocery);
-                $s->xact_type( 'circulation' ) if ($x->circulation);
-
-                push @mbts, $s;
-        }
-
-        return @mbts;
-}
-
 
 __PACKAGE__->register_method (
        method => 'fetch_mbts',
        api_name => 'open-ils.circ.money.billable_xact_summary.retrieve'
 );
 sub fetch_mbts {
-       my($s, $c, $authtoken, $id) = @_;
-
-       $id = $id->id if (ref($id));
+       my( $self, $conn, $auth, $id) = @_;
 
-        my @xacts = @{ $U->cstorereq(
-               'open-ils.cstore.direct.money.billable_transaction.search.atomic',
-                { id => $id },
-                { flesh => 1, flesh_fields => { mbt => [ qw/billings payments grocery circulation/ ] } }
-       ) };
-
-       my ($sum) = _make_mbts(@xacts);
-       return OpenILS::Event->new('MONEY_BILLABLE_TRANSACTION_SUMMARY_NOT_FOUND', id => $id) unless $sum;
-
-       my ($reqr, $evt) = $U->checkses($authtoken);
-       return $evt if $evt;
+       my $e = new_editor(xact => 1, authtoken=>$auth);
+       return $e->event unless $e->checkauth;
+       my ($mbts) = $U->fetch_mbts($id, $e);
 
-       my $usr;
-       ($usr, $evt) = $U->fetch_user($sum->usr);
-       return $evt if $evt;
+       my $user = $e->retrieve_actor_user($mbts->usr)
+               or return $e->die_event;
 
-       $evt = $U->check_perms($reqr->id, $usr->home_ou, 'VIEW_TRANSACTION');
-       return $evt if $evt;
-
-       return $sum;
+       return $e->die_event unless $e->allowed('VIEW_TRANSACTION', $user->home_ou);
+       $e->rollback;
+       return $mbts
 }
 
 
+
 __PACKAGE__->register_method(
        method => 'desk_payments',
        api_name => 'open-ils.circ.money.org_unit.desk_payments'