adding a billing to a closed transaction now re-opens the transaction
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 14 Jun 2006 19:09:26 +0000 (19:09 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 14 Jun 2006 19:09:26 +0000 (19:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4616 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 0142ec8..fa3e2c1 100644 (file)
@@ -26,7 +26,7 @@ use OpenILS::Perm;
 use Data::Dumper;
 use OpenSRF::Utils::Logger qw/:logger/;
 use OpenILS::Event;
-use OpenILS::Utils::Editor;
+use OpenILS::Utils::Editor qw/:funcs/;
 
 __PACKAGE__->register_method(
        method  => "make_payments",
@@ -290,19 +290,24 @@ __PACKAGE__->register_method(
 sub billing_items_create {
        my( $self, $client, $login, $billing ) = @_;
 
-       my( $staff, $evt ) = $apputils->checksesperm($login, 'CREATE_BILL');
-       return $evt if $evt;
-
-       my $session = $apputils->start_db_session;
+       my $e = new_editor(authtoken => $login, xact => 1);
+       return $e->event unless $e->checkauth;
+       return $e->event unless $e->allowed('CREATE_BILL');
 
-       my $id = $session->request(
-               'open-ils.storage.direct.money.billing.create', $billing )->gather(1);
+       my $xact = $e->retrieve_money_billable_transaction($billing->xact)
+               or return $e->event;
 
-       return $U->DB_UPDATE_FAILED($billing) unless defined $id;
+       # if the transaction was closed, re-open it
+       if($xact->xact_finish) {
+               $xact->clear_xact_finish;
+               $e->update_money_billable_transaction($xact)
+                       or return $e->event;
+       }
 
-       $apputils->commit_db_session($session);
+       $e->create_money_billing($billing) or return $e->event;
 
-       return $id;
+       $e->commit;
+       return $billing->id;
 }
 
 __PACKAGE__->register_method(
@@ -371,6 +376,7 @@ sub _check_open_xact {
        return undef;
 }
 
+
 __PACKAGE__->register_method (
        method => 'fetch_mbts',
        api_name => 'open-ils.circ.money.billable_xact_summary.retrieve'