cust_credit reason improvement, bugfix, and tool
authorjeff <jeff>
Wed, 12 Dec 2007 05:43:56 +0000 (05:43 +0000)
committerjeff <jeff>
Wed, 12 Dec 2007 05:43:56 +0000 (05:43 +0000)
FS/FS/cust_credit.pm
FS/FS/h_cust_credit.pm [new file with mode: 0644]
FS/bin/freeside-disable-reasons [new file with mode: 0755]
FS/bin/freeside-upgrade

index 96bf8ef..cbdc71d 100644 (file)
@@ -280,7 +280,7 @@ sub check {
 
   $self->_date(time) unless $self->_date;
 
-  $self->otaker(getotaker);
+  $self->otaker(getotaker) unless ($self->otaker);
 
   $self->SUPER::check;
 }
@@ -388,6 +388,7 @@ sub reason {
     if (!$reason && $typenum) {
       $reason = new FS::reason( { 'reason_type' => $typenum,
                                   'reason' => $value,
+                                  'disabled' => 'Y', 
                               } );
       $reason->insert and $reason = undef;
     }
@@ -439,6 +440,7 @@ sub _upgrade_data {  # class method
                  };
       my $noreason = qsearchs( 'reason', $hashref );
       unless ($noreason) {
+        $hashref->{'disabled'} = 'Y';
         $noreason = new FS::reason( $hashref );
         my $error  = $noreason->insert();
         die "can't insert legacy reason '(none)' into database: $error\n"
diff --git a/FS/FS/h_cust_credit.pm b/FS/FS/h_cust_credit.pm
new file mode 100644 (file)
index 0000000..1425a26
--- /dev/null
@@ -0,0 +1,33 @@
+package FS::h_cust_credit;
+
+use strict;
+use vars qw( @ISA );
+use FS::h_Common;
+use FS::cust_credit;
+
+@ISA = qw( FS::h_Common FS::cust_credit );
+
+sub table { 'h_cust_credit' };
+
+=head1 NAME
+
+FS::h_cust_credit - Historical record of customer credit changes
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+An FS::h_cust_credit object represents historical changes to credits.
+FS::h_cust_credit inherits from FS::h_Common and FS::cust_credit.
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::cust_credit>,  L<FS::h_Common>, L<FS::Record>, schema.html from the base
+documentation.
+
+=cut
+
+1;
+
diff --git a/FS/bin/freeside-disable-reasons b/FS/bin/freeside-disable-reasons
new file mode 100755 (executable)
index 0000000..0af4609
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/perl -w
+
+use strict;
+use vars qw($opt_t $opt_e);
+use Getopt::Std;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch qsearchs);
+use FS::reason_type;
+use FS::reason;
+
+getopts('t:e');
+
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+die &usage
+  unless ($opt_t);
+
+$FS::Record::nowarn_identical = 1;
+
+my @reason = ();
+if ( $opt_t ) {
+  $opt_t =~ /^(\d+)$/ or die "invalid reason_type";
+  @reason = qsearch('reason', { reason_type => $1 } );
+  die "no reasons found\n" unless @reason;
+} else {
+  die "no reason_type specified\n";
+}
+
+foreach my $reason ( @reason ) {
+  if ( $opt_e ) {
+    $reason->disabled('');
+  }else{
+    $reason->disabled('Y');
+  }
+  my $error = $reason->replace
+    if $reason->modified;     
+  die $error if $error;
+}
+
+
+sub usage {
+  die "Usage:\n\n  freeside-disable-reasons -t reason_type [ -e ] user\n";
+}
+
+=head1 NAME
+
+freeside-disable-reasons - Command line tool to set the disabled column for reasons
+
+=head1 SYNOPSIS
+
+  freeside-disable-reasons -t reason_type [ -e ] user
+
+=head1 DESCRIPTION
+
+  Disables the reasons of the specified reason type.
+  Enables instead if -e is specified.
+
+=head1 SEE ALSO
+
+L<FS::reason>, L<FS::reason_type>
+
+=cut
+
index fa9f900..04bcb23 100755 (executable)
@@ -93,6 +93,11 @@ if ( $dbh->{Driver}->{Name} =~ /^mysql/i ) {
   }
 }
 
+$dbh->commit or die $dbh->errstr;  # we *MUST* commit before upgrading data
+dbdef_create($dbh, $dbdef_file);
+delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload
+reload_dbdef($dbdef_file);
+
 upgrade()
   unless $DRY_RUN;