add in-db billing type support
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Dec 2008 17:04:22 +0000 (17:04 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Dec 2008 17:04:22 +0000 (17:04 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11389 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/OpenILS/Application/Collections.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/money.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/src/sql/Pg/080.schema.money.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql

index 21b9dcc..fe80332 100644 (file)
@@ -3385,17 +3385,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
                        <field reporter:label="Amount" name="amount" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="money" />
                        <field reporter:label="Billing Timestamp" name="billing_ts" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="timestamp"/>
-                       <field reporter:label="Billing Type" name="billing_type" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text"/>
+                       <field reporter:label="Legacy Billing Type" name="billing_type" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text"/>
                        <field reporter:label="Billing ID" name="id" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="id" />
                        <field reporter:label="Note" name="note" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="text"/>
                        <field reporter:label="Void Timestamp" name="void_time" oils_obj:array_position="8" oils_persist:virtual="false" reporter:datatype="timestamp"/>
                        <field reporter:label="Voided?" name="voided" oils_obj:array_position="9" oils_persist:virtual="false" reporter:datatype="bool"/>
                        <field reporter:label="Voiding Staff Member" name="voider" oils_obj:array_position="10" oils_persist:virtual="false" reporter:datatype="link"/>
                        <field reporter:label="Transaction" name="xact" oils_obj:array_position="11" oils_persist:virtual="false" reporter:datatype="link"/>
+                       <field reporter:label="Type" name="btype" oils_obj:array_position="12" oils_persist:virtual="false" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="xact" reltype="has_a" key="id" map="" class="mbt"/>
                        <link field="voider" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="btype" reltype="has_a" key="id" map="" class="cbt"/>
                </links>
        </class>
        <class id="pugm" controller="open-ils.cstore" oils_obj:fieldmapper="permission::usr_grp_map" oils_persist:tablename="permission.usr_grp_map">
index 93db5b5..f33f5c6 100644 (file)
@@ -293,14 +293,14 @@ sub new_set_circ_lost {
     my $price = $U->get_copy_price($e, $copy, $copy->call_number);
 
     if( $price > 0 ) {
-        my $evt = create_bill($e, $price, 'Lost Materials', $circ->id);
+        my $evt = create_bill($e, $price, 3, 'Lost Materials', $circ->id);
         return $evt if $evt;
     }
 
     # ---------------------------------------------------------------------
     # if there is a processing fee, charge that too
     if( $proc_fee > 0 ) {
-        my $evt = create_bill($e, $proc_fee, 'Lost Materials Processing Fee', $circ->id);
+        my $evt = create_bill($e, $proc_fee, 4, 'Lost Materials Processing Fee', $circ->id);
         return $evt if $evt;
     }
 
@@ -347,7 +347,7 @@ sub reopen_xact {
 
 
 sub create_bill {
-       my( $e, $amount, $type, $xactid ) = @_;
+       my( $e, $amount, $btype, $type, $xactid ) = @_;
 
        $logger->info("The system is charging $amount [$type] on xact $xactid");
 
@@ -357,6 +357,7 @@ sub create_bill {
        $bill->xact($xactid);
        $bill->amount($amount);
        $bill->billing_type($type); 
+       $bill->btype($btype); 
        $bill->note('SYSTEM GENERATED');
     $e->create_money_billing($bill) or return $e->die_event;
 
@@ -374,7 +375,7 @@ sub void_overdues {
 
     my $bill_search = { 
         xact => $circ->id, 
-        billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS 
+        btype => 1 
     };
 
     if( $backdate ) {
index a61b67a..24f7fd8 100644 (file)
@@ -1194,12 +1194,15 @@ sub apply_deposit_fee {
        my $bill = Fieldmapper::money::billing->new;
     my $amount = $copy->deposit_amount;
     my $billing_type;
+    my $btype;
 
     if($self->is_deposit) {
         $billing_type = OILS_BILLING_TYPE_DEPOSIT;
+        $btype = 5;
         $self->deposit_billing($bill);
     } else {
         $billing_type = OILS_BILLING_TYPE_RENTAL;
+        $btype = 6;
         $self->rental_billing($bill);
     }
 
@@ -1207,6 +1210,7 @@ sub apply_deposit_fee {
        $bill->amount($amount);
        $bill->note(OILS_BILLING_NOTE_SYSTEM);
        $bill->billing_type($billing_type);
+       $bill->btype($btype);
     $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");
@@ -1758,7 +1762,7 @@ sub check_circ_deposit {
     my $self = shift;
     return unless $self->circ;
     my $deposit = $self->editor->search_money_billing(
-        {   billing_type => OILS_BILLING_TYPE_DEPOSIT
+        {   btype => 5
             xact => $self->circ->id, 
             voided => 'f'
         }, {idlist => 1})->[0];
@@ -2139,7 +2143,7 @@ sub checkin_handle_backdate {
         { 
             billing_ts => { '>=' => $bd }, 
             xact => $self->circ->id, 
-            billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
+            btype => 1
         }
     );
 
index 09cf561..050a9d1 100644 (file)
@@ -435,6 +435,7 @@ sub add_collections_fee {
        my $bill = Fieldmapper::money::billing->new;
        $bill->note($fee_note);
        $bill->xact($xact->id);
+       $bill->btype(2);
        $bill->billing_type(OILS_BILLING_TYPE_COLLECTION_FEE);
        $bill->amount($fee_amount);
 
index 5e32636..ab21f84 100644 (file)
@@ -79,7 +79,8 @@ package money::billing;
 use base qw/money/;
 __PACKAGE__->table('money_billing');
 __PACKAGE__->columns(Primary => 'id');
-__PACKAGE__->columns(Essential => qw/xact amount billing_ts billing_type note voided voider void_time/);
+__PACKAGE__->columns(Essential => qw/xact amount billing_ts billing_type note
+                                     voided voider void_time btype/);
 #-------------------------------------------------------------------------------
 
 package money::payment;
index 8068e45..439b889 100644 (file)
@@ -640,7 +640,7 @@ sub generate_fines {
        
                        my @fines = money::billing->search_where(
                                { xact => $c->id,
-                                 billing_type => 'Overdue materials',
+                                 btype => 1,
                                  billing_ts => { '>' => $c->due_date } },
                                { order_by => 'billing_ts DESC'}
                        );
@@ -752,6 +752,7 @@ sub generate_fines {
                                        { xact          => ''.$c->id,
                                          note          => "System Generated Overdue Fine",
                                          billing_type  => "Overdue materials",
+                                         btype         => 1,
                                          amount        => sprintf('%0.2f', $recuring_fine/100),
                                          billing_ts    => $timestamptz,
                                        }
index 34c2dab..a585865 100644 (file)
@@ -56,6 +56,7 @@ CREATE TABLE money.billing (
        void_time       TIMESTAMP WITH TIME ZONE,
        amount          NUMERIC(6,2)                    NOT NULL,
        billing_type    TEXT                            NOT NULL,
+       btype           INT                             NOT NULL REFERENCES config.billing_type (id) ON DELETE RESTRICT,
        note            TEXT
 );
 CREATE INDEX m_b_xact_idx ON money.billing (xact);
index 27b7b45..129aa3c 100644 (file)
@@ -805,6 +805,21 @@ INSERT INTO actor.org_unit_type (id, name, opac_label, depth, parent) VALUES
        oils_i18n_gettext(5, 'Your Bookmobile', 'aout', 'opac_label'), 3, 3 );
 SELECT SETVAL('actor.org_unit_type_id_seq'::TEXT, 100);
 
+INSERT INTO config.billing_type (id, name, owner) VALUES
+       ( 1, oils_i18n_gettext(1, 'Overdue Materials', 'cbt', 'name'), 1);
+INSERT INTO config.billing_type (id, name, owner) VALUES
+       ( 2, oils_i18n_gettext(2, 'Long Overdue Collection Fee', 'cbt', 'name'), 1);
+INSERT INTO config.billing_type (id, name, owner) VALUES
+       ( 3, oils_i18n_gettext(3, 'Lost Materials', 'cbt', 'name'), 1);
+INSERT INTO config.billing_type (id, name, owner) VALUES
+       ( 4, oils_i18n_gettext(4, 'Lost Materials Processing Fee', 'cbt', 'name'), 1);
+INSERT INTO config.billing_type (id, name, owner) VALUES
+       ( 5, oils_i18n_gettext(5, 'System: Deposit', 'cbt', 'name'), 1);
+INSERT INTO config.billing_type (id, name, owner) VALUES
+       ( 6, oils_i18n_gettext(6, 'System: Rental', 'cbt', 'name'), 1);
+
+SELECT SETVAL('config.billing_type_id_seq'::TEXT, 100);
+
 INSERT INTO actor.org_unit (id, parent_ou, ou_type, shortname, name) VALUES 
     (1, NULL, 1, 'CONS', oils_i18n_gettext(1, 'Example Consortium', 'aou', 'name'));
 INSERT INTO actor.org_unit (id, parent_ou, ou_type, shortname, name) VALUES