added support for deposit/rental billing at checkout time based on item deposit ...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 22 Sep 2008 16:38:03 +0000 (16:38 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 22 Sep 2008 16:38:03 +0000 (16:38 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@10684 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/OpenILS/Const.pm

index 2e445ff..b948b41 100644 (file)
        <event code='1231' textcode='RECORD_NOT_EMPTY'>
                <desc xml:lang="en-US">The selected bib record has volumes attached</desc>
        </event>
        <event code='1231' textcode='RECORD_NOT_EMPTY'>
                <desc xml:lang="en-US">The selected bib record has volumes attached</desc>
        </event>
+       <event code='1232' textcode='ITEM_DEPOSIT_REQUIRED'>
+               <desc xml:lang="en-US"></desc>
+       </event>
+       <event code='1233' textcode='ITEM_RENTAL_FEE_REQUIRED'>
+               <desc xml:lang="en-US"></desc>
+       </event>
+       <event code='1234' textcode='ITEM_DEPOSIT_PAID'>
+               <desc xml:lang="en-US"></desc>
+       </event>
 
 
 
 
 
 
index aebcf90..d22a8c2 100644 (file)
@@ -386,6 +386,10 @@ my @AUTOLOAD_FIELDS = qw/
     circ_matrix_test
     circ_matrix_ruleset
     legacy_script_support
     circ_matrix_test
     circ_matrix_ruleset
     legacy_script_support
+    is_deposit
+    is_rental
+    deposit_billing
+    rental_billing
 /;
 
 
 /;
 
 
@@ -513,6 +517,10 @@ sub mk_env {
             $self->copy->call_number($self->volume->id);
             $self->volume->record($self->title->id);
             $self->is_precat(1) if $self->volume->id == OILS_PRECAT_CALL_NUMBER;
             $self->copy->call_number($self->volume->id);
             $self->volume->record($self->title->id);
             $self->is_precat(1) if $self->volume->id == OILS_PRECAT_CALL_NUMBER;
+            if($self->copy->deposit_amount and $self->copy->deposit_amount > 0) {
+                $self->is_deposit(1) if $U->is_true($self->copy->deposit);
+                $self->is_rental(1) unless $U->is_true($self->copy->deposit);
+            }
         } else {
             # We can't renew if there is no copy
             return $self->bail_on_events(OpenILS::Event->new('ASSET_COPY_NOT_FOUND'))
         } else {
             # We can't renew if there is no copy
             return $self->bail_on_events(OpenILS::Event->new('ASSET_COPY_NOT_FOUND'))
@@ -604,8 +612,13 @@ sub mk_script_runner {
         }
     }
 
         }
     }
 
-    $self->is_precat(1) if $self->copy 
-        and $self->copy->call_number == OILS_PRECAT_CALL_NUMBER;
+    if($self->copy) {
+        $self->is_precat(1) if $self->copy->call_number == OILS_PRECAT_CALL_NUMBER;
+        if($self->copy->deposit_amount and $self->copy->deposit_amount > 0) {
+            $self->is_deposit(1) if $U->is_true($self->copy->deposit);
+            $self->is_rental(1) unless $U->is_true($self->copy->deposit);
+        }
+    }
 
     # We can't renew if there is no copy
     return $self->bail_on_events(@evts) if 
 
     # We can't renew if there is no copy
     return $self->bail_on_events(@evts) if 
@@ -648,6 +661,7 @@ sub do_permit {
     $self->run_patron_permit_scripts();
     $self->run_copy_permit_scripts() 
         unless $self->is_precat or $self->is_noncat;
     $self->run_patron_permit_scripts();
     $self->run_copy_permit_scripts() 
         unless $self->is_precat or $self->is_noncat;
+    $self->check_item_deposit_events();
     $self->override_events() unless 
         $self->is_renewal and not $self->check_penalty_on_renew;
     return if $self->bail_out;
     $self->override_events() unless 
         $self->is_renewal and not $self->check_penalty_on_renew;
     return if $self->bail_out;
@@ -665,6 +679,11 @@ sub do_permit {
             payload => $self->mk_permit_key));
 }
 
             payload => $self->mk_permit_key));
 }
 
+sub check_item_deposit_events {
+    my $self = shift;
+    $self->push_events(OpenILS::Event->new('ITEM_DEPOSIT_REQUIRED')) if $self->is_deposit;
+    $self->push_events(OpenILS::Event->new('ITEM_RENTAL_FEE_REQUIRED')) if $self->is_rental;
+}
 
 sub check_captured_holds {
    my $self    = shift;
 
 sub check_captured_holds {
    my $self    = shift;
@@ -1142,6 +1161,9 @@ sub do_checkout {
     $self->update_copy;
     return if $self->bail_out;
 
     $self->update_copy;
     return if $self->bail_out;
 
+    $self->apply_deposit_fee();
+    return if $self->bail_out;
+
     $self->handle_checkout_holds();
     return if $self->bail_out;
 
     $self->handle_checkout_holds();
     return if $self->bail_out;
 
@@ -1166,11 +1188,39 @@ sub do_checkout {
                 circ              => $self->circ,
                 record            => $record,
                 holds_fulfilled   => $self->fulfilled_holds,
                 circ              => $self->circ,
                 record            => $record,
                 holds_fulfilled   => $self->fulfilled_holds,
+                deposit_bill      => $self->deposit_billing,
+                rental_bill       => $self->rental_billing
             }
         )
     );
 }
 
             }
         )
     );
 }
 
+sub apply_deposit_fee {
+    my $self = shift;
+    my $copy = $self->copy;
+    return unless $self->is_deposit or $self->is_rental;
+
+       my $bill = Fieldmapper::money::billing->new;
+    my $amount = $copy->deposit_amount;
+    my $billing_type;
+
+    if($self->is_deposit) {
+        $billing_type = OILS_BILLING_TYPE_DEPOSIT;
+        $self->deposit_billing($bill);
+    } else {
+        $billing_type = OILS_BILLING_TYPE_RENTAL;
+        $self->rental_billing($bill);
+    }
+
+       $bill->xact($self->circ->id);
+       $bill->amount($amount);
+       $bill->note(OILS_BILLING_NOTE_SYSTEM);
+       $bill->billing_type($billing_type);
+    $self->editor->create_money_billing($bill) or $self->bail_on_events($self->editor->event);
+
+       $logger->info("circulator: charged $amount on checkout with billing type $billing_type");
+}
+
 sub update_copy {
     my $self = shift;
     my $copy = $self->copy;
 sub update_copy {
     my $self = shift;
     my $copy = $self->copy;
@@ -1573,6 +1623,8 @@ sub do_checkin {
         if ($self->circ and $self->circ->stop_fines 
                 and $self->circ->stop_fines eq OILS_STOP_FINES_CLAIMSRETURNED);
 
         if ($self->circ and $self->circ->stop_fines 
                 and $self->circ->stop_fines eq OILS_STOP_FINES_CLAIMSRETURNED);
 
+    $self->check_circ_deposit();
+
     # handle the overridable events 
     $self->override_events unless $self->is_renewal;
     return if $self->bail_out;
     # handle the overridable events 
     $self->override_events unless $self->is_renewal;
     return if $self->bail_out;
@@ -1715,6 +1767,20 @@ sub do_checkin {
     return;
 }
 
     return;
 }
 
+# if a deposit was payed for this item, push the event
+sub check_circ_deposit {
+    my $self = shift;
+    return unless $self->circ;
+    my $deposit = $self->editor->search_money_billing(
+        {   billing_type => OILS_BILLING_TYPE_DEPOSIT, 
+            xact => $self->circ->id, 
+            voided => 'f'
+        }, {idlist => 1})->[0];
+
+    $self->push_events(OpenILS::Event->new(
+        'ITEM_DEPOSIT_PAID', payload => $deposit)) if $deposit;
+}
+
 sub reshelve_copy {
    my $self    = shift;
    my $force   = $self->force || shift;
 sub reshelve_copy {
    my $self    = shift;
    my $force   = $self->force || shift;
index 28ca6dc..145060a 100644 (file)
@@ -93,6 +93,9 @@ econst OILS_HOLD_TYPE_METARECORD  => 'M';
 
 econst OILS_BILLING_TYPE_OVERDUE_MATERIALS => 'Overdue materials';
 econst OILS_BILLING_TYPE_COLLECTION_FEE => 'Long Overdue Collection Fee';
 
 econst OILS_BILLING_TYPE_OVERDUE_MATERIALS => 'Overdue materials';
 econst OILS_BILLING_TYPE_COLLECTION_FEE => 'Long Overdue Collection Fee';
+econst OILS_BILLING_TYPE_DEPOSIT => 'System: Deposit';
+econst OILS_BILLING_TYPE_RENTAL => 'System: Rental';
+econst OILS_BILLING_NOTE_SYSTEM => 'SYSTEM GENERATED';