Changes to add classified reasons for invoice void
authorIrina Todeva <itodeva@hostgator.com>
Wed, 30 Sep 2015 20:35:07 +0000 (14:35 -0600)
committerMark Wells <mark@freeside.biz>
Tue, 3 Nov 2015 20:28:13 +0000 (12:28 -0800)
 - Added reasonnum and a corresponding foreign key in cust_bill_void and
   cust_bill_pkg_void tables (Schema.pm)
 - Used the FS::reason_Mixin::reason as the override of the
   cust_bill_void->reason to handle legacy and classified reasons
 - Changes in voided_invoice.html template to handle classified reasons for
   void invoices

FS/FS/Schema.pm
FS/FS/cust_bill.pm
FS/FS/cust_bill_pkg.pm
FS/FS/cust_bill_pkg_void.pm
FS/FS/cust_bill_void.pm
httemplate/view/cust_main/payment_history/voided_invoice.html

index c9ab5bc..6b5d658 100644 (file)
@@ -735,8 +735,9 @@ sub tables_hashref {
 
         #void fields
         'void_date', @date_type, '', '', 
 
         #void fields
         'void_date', @date_type, '', '', 
-        'reason',    'varchar',   'NULL', $char_d, '', '', 
-        'void_usernum',   'int', 'NULL', '', '', '',
+        'reason',     'varchar', 'NULL', $char_d, '', '', 
+        'reasonnum',      'int', 'NULL',      '', '', '',
+        'void_usernum',   'int', 'NULL',      '', '', '',
       ],
       'primary_key'  => 'invnum',
       'unique'       => [ [ 'custnum', 'agent_invid' ] ], #agentnum?  huh
       ],
       'primary_key'  => 'invnum',
       'unique'       => [ [ 'custnum', 'agent_invid' ] ], #agentnum?  huh
@@ -750,6 +751,9 @@ sub tables_hashref {
                           { columns    => [ 'statementnum' ],
                             table      => 'cust_statement', #_void? both?
                           },
                           { columns    => [ 'statementnum' ],
                             table      => 'cust_statement', #_void? both?
                           },
+                          { columns    => [ 'reasonnum' ],
+                            table      => 'reason',
+                          },
                           { columns    => [ 'void_usernum' ],
                             table      => 'access_user',
                             references => [ 'usernum' ],
                           { columns    => [ 'void_usernum' ],
                             table      => 'access_user',
                             references => [ 'usernum' ],
@@ -1197,8 +1201,9 @@ sub tables_hashref {
         'feepart',              'int', 'NULL',      '', '', '',
         #void fields
         'void_date', @date_type, '', '', 
         'feepart',              'int', 'NULL',      '', '', '',
         #void fields
         'void_date', @date_type, '', '', 
-        'reason',    'varchar',   'NULL', $char_d, '', '', 
-        'void_usernum',   'int', 'NULL', '', '', '',
+        'reason',     'varchar', 'NULL', $char_d, '', '', 
+        'reasonnum',      'int', 'NULL',      '', '', '',
+        'void_usernum',   'int', 'NULL',      '', '', '',
       ],
       'primary_key'  => 'billpkgnum',
       'unique'       => [],
       ],
       'primary_key'  => 'billpkgnum',
       'unique'       => [],
@@ -1209,6 +1214,9 @@ sub tables_hashref {
                           { columns    => [ 'invnum' ],
                             table      => 'cust_bill_void',
                           },
                           { columns    => [ 'invnum' ],
                             table      => 'cust_bill_void',
                           },
+                          { columns    => [ 'reasonnum' ],
+                            table      => 'reason',
+                          },
                           #pkgnum 0 and -1 are used for special things
                           #{ columns    => [ 'pkgnum' ],
                           #  table      => 'cust_pkg',
                           #pkgnum 0 and -1 are used for special things
                           #{ columns    => [ 'pkgnum' ],
                           #  table      => 'cust_pkg',
index 6546bfa..138d0fa 100644 (file)
@@ -37,6 +37,8 @@ use FS::cust_bill_pay_pkg;
 use FS::cust_credit_bill_pkg;
 use FS::discount_plan;
 use FS::cust_bill_void;
 use FS::cust_credit_bill_pkg;
 use FS::discount_plan;
 use FS::cust_bill_void;
+use FS::reason;
+use FS::reason_type;
 use FS::L10N;
 
 $DEBUG = 0;
 use FS::L10N;
 
 $DEBUG = 0;
@@ -212,7 +214,7 @@ sub insert {
 
 }
 
 
 }
 
-=item void
+=item void [ REASON ]
 
 Voids this invoice: deletes the invoice and adds a record of the voided invoice
 to the FS::cust_bill_void table (and related tables starting from
 
 Voids this invoice: deletes the invoice and adds a record of the voided invoice
 to the FS::cust_bill_void table (and related tables starting from
@@ -224,6 +226,14 @@ sub void {
   my $self = shift;
   my $reason = scalar(@_) ? shift : '';
 
   my $self = shift;
   my $reason = scalar(@_) ? shift : '';
 
+  unless (ref($reason) || !$reason) {
+    $reason = FS::reason->new_or_existing(
+      'class'  => 'X',
+      'type'   => 'Void invoice',
+      'reason' => $reason
+    );
+  }
+
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
@@ -238,7 +248,7 @@ sub void {
   my $cust_bill_void = new FS::cust_bill_void ( {
     map { $_ => $self->get($_) } $self->fields
   } );
   my $cust_bill_void = new FS::cust_bill_void ( {
     map { $_ => $self->get($_) } $self->fields
   } );
-  $cust_bill_void->reason($reason);
+  $cust_bill_void->reasonnum($reason->reasonnum) if $reason;
   my $error = $cust_bill_void->insert;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
   my $error = $cust_bill_void->insert;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
index 5861ee4..aea776a 100644 (file)
@@ -26,6 +26,8 @@ use FS::cust_bill_pkg_tax_location_void;
 use FS::cust_bill_pkg_tax_rate_location_void;
 use FS::cust_tax_exempt_pkg_void;
 use FS::cust_bill_pkg_fee_void;
 use FS::cust_bill_pkg_tax_rate_location_void;
 use FS::cust_tax_exempt_pkg_void;
 use FS::cust_bill_pkg_fee_void;
+use FS::reason;
+use FS::reason_type;
 
 use FS::Cursor;
 
 
 use FS::Cursor;
 
@@ -322,7 +324,7 @@ sub insert {
 
 }
 
 
 }
 
-=item void
+=item void [ REASON ]
 
 Voids this line item: deletes the line item and adds a record of the voided
 line item to the FS::cust_bill_pkg_void table (and related tables).
 
 Voids this line item: deletes the line item and adds a record of the voided
 line item to the FS::cust_bill_pkg_void table (and related tables).
@@ -333,6 +335,14 @@ sub void {
   my $self = shift;
   my $reason = scalar(@_) ? shift : '';
 
   my $self = shift;
   my $reason = scalar(@_) ? shift : '';
 
+  unless (ref($reason) || !$reason) {
+    $reason = FS::reason->new_or_existing(
+      'class'  => 'X',
+      'type'   => 'Void invoice',
+      'reason' => $reason
+    );
+  }
+
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
@@ -347,7 +357,7 @@ sub void {
   my $cust_bill_pkg_void = new FS::cust_bill_pkg_void ( {
     map { $_ => $self->get($_) } $self->fields
   } );
   my $cust_bill_pkg_void = new FS::cust_bill_pkg_void ( {
     map { $_ => $self->get($_) } $self->fields
   } );
-  $cust_bill_pkg_void->reason($reason);
+  $cust_bill_pkg_void->reasonnum($reason->reasonnum) if $reason;
   my $error = $cust_bill_pkg_void->insert;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
   my $error = $cust_bill_pkg_void->insert;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
index 080452e..4b9cffd 100644 (file)
@@ -1,5 +1,5 @@
 package FS::cust_bill_pkg_void;
 package FS::cust_bill_pkg_void;
-use base qw( FS::TemplateItem_Mixin FS::Record );
+use base qw( FS::TemplateItem_Mixin FS::reason_Mixin FS::Record );
 
 use strict;
 use FS::Record qw( qsearch qsearchs dbh fields );
 
 use strict;
 use FS::Record qw( qsearch qsearchs dbh fields );
@@ -104,6 +104,13 @@ unitrecur
 
 hidden
 
 
 hidden
 
+=item reason 
+
+freeform string (deprecated)
+
+=item reasonnum 
+
+reason for voiding the payment (see L<FS::reson>)
 
 =back
 
 
 =back
 
@@ -134,6 +141,10 @@ sub discount_table          { 'cust_bill_pkg_discount_void'; }
 Adds this record to the database.  If there is an error, returns the error,
 otherwise returns false.
 
 Adds this record to the database.  If there is an error, returns the error,
 otherwise returns false.
 
+=item reason
+
+Returns the text of the associated void reason (see L<FS::reason>) for this.
+
 =item unvoid 
 
 "Un-void"s this line item: Deletes the voided line item from the database and
 =item unvoid 
 
 "Un-void"s this line item: Deletes the voided line item from the database and
@@ -242,6 +253,8 @@ sub check {
     || $self->ut_moneyn('unitrecur')
     || $self->ut_enum('hidden', [ '', 'Y' ])
     || $self->ut_numbern('feepart')
     || $self->ut_moneyn('unitrecur')
     || $self->ut_enum('hidden', [ '', 'Y' ])
     || $self->ut_numbern('feepart')
+    || $self->ut_textn('reason')
+    || $self->ut_foreign_keyn('reasonnum', 'reason', 'reasonnum')
   ;
   return $error if $error;
 
   ;
   return $error if $error;
 
index f3dba90..04c69d4 100644 (file)
@@ -1,5 +1,6 @@
 package FS::cust_bill_void;
 package FS::cust_bill_void;
-use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::otaker_Mixin FS::Record );
+use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::otaker_Mixin
+             FS::reason_Mixin FS::Record );
 
 use strict;
 use FS::Record qw( qsearch qsearchs dbh fields );
 
 use strict;
 use FS::Record qw( qsearch qsearchs dbh fields );
@@ -82,9 +83,13 @@ promised_date
 
 void_date
 
 
 void_date
 
-=item reason
+=item reason 
+
+freeform string (deprecated)
+
+=item reasonnum 
 
 
-reason
+reason for voiding the payment (see L<FS::reson>)
 
 =item void_usernum
 
 
 =item void_usernum
 
@@ -216,6 +221,7 @@ sub check {
     || $self->ut_numbern('void_date')
     || $self->ut_textn('reason')
     || $self->ut_numbern('void_usernum')
     || $self->ut_numbern('void_date')
     || $self->ut_textn('reason')
     || $self->ut_numbern('void_usernum')
+    || $self->ut_foreign_keyn('reasonnum', 'reason', 'reasonnum')
   ;
   return $error if $error;
 
   ;
   return $error if $error;
 
@@ -259,6 +265,10 @@ sub void_access_user {
 
 =item cust_bill_pkg
 
 
 =item cust_bill_pkg
 
+=item reason
+
+Returns the text of the associated void reason (see L<FS::reason>) for this.
+
 =cut
 
 sub cust_bill_pkg { #actually cust_bill_pkg_void objects
 =cut
 
 sub cust_bill_pkg { #actually cust_bill_pkg_void objects
index ea61f84..ff4d12f 100644 (file)
@@ -6,7 +6,7 @@
 % }
 % my $reason = $cust_bill_void->reason;
 % if ($reason) {
 % }
 % my $reason = $cust_bill_void->reason;
 % if ($reason) {
-     (<% $reason %>)
+     (<% $reason |h %>)
 % }
 <% mt("on [_1]", time2str($date_format, $cust_bill_void->void_date) ) |h %> 
 </I>
 % }
 <% mt("on [_1]", time2str($date_format, $cust_bill_void->void_date) ) |h %> 
 </I>