X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_refund.pm;h=12ab0d693316048b36fd2fc2c47658a50f71e3eb;hp=e3fc910ec177750e8e3c12ae9c76c4c71490f8ee;hb=d2485c6fa278d7a4a1c940605816013f41d1f7e0;hpb=9ac90646828dd34b49fc2474c9666ba33c3508a4 diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index e3fc910ec..12ab0d693 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -82,6 +82,10 @@ Payment Type (See L for valid payby values) Payment Information (See L for data format) +=item paycardtype + +Detected credit card type, if appropriate; autodetected. + =item paymask Masked payinfo (See L for how this works) @@ -143,16 +147,23 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - unless ($self->reasonnum) { - my $result = $self->reason( $self->getfield('reason'), - exists($options{ 'reason_type' }) - ? ('reason_type' => $options{ 'reason_type' }) - : (), - ); - unless($result) { + if (!$self->reasonnum) { + my $reason_text = $self->get('reason') + or return "reason text or existing reason required"; + my $reason_type = $options{'reason_type'} + or return "reason type required"; + + local $@; + my $reason = FS::reason->new_or_existing( + reason => $reason_text, + type => $reason_type, + class => 'F', + ); + if ($@) { $dbh->rollback if $oldAutoCommit; - return "failed to set reason for $me"; #: ". $dbh->errstr; + return "failed to set refund reason: $@"; } + $self->set('reasonnum', $reason->reasonnum); } $self->setfield('reason', ''); @@ -278,7 +289,8 @@ otherwise returns false. sub replace { my $self = shift; - return "Can't modify closed refund" if $self->closed =~ /^Y/i; + return "Can't modify closed refund" + if $self->closed =~ /^Y/i && !$FS::payinfo_Mixin::allow_closed_replace; $self->SUPER::replace(@_); } @@ -303,6 +315,7 @@ sub check { || $self->ut_numbern('_date') || $self->ut_textn('paybatch') || $self->ut_enum('closed', [ '', 'Y' ]) + || $self->ut_foreign_keyn('source_paynum', 'cust_pay', 'paynum') ; return $error if $error; @@ -370,6 +383,59 @@ sub unapplied { sprintf("%.2f", $amount ); } +=item send_receipt HASHREF | OPTION => VALUE ... + +Sends a payment receipt for this payment. + +refund_receipt_msgnum must be configured. + +Available options: + +=over 4 + +=item cust_main + +Customer (FS::cust_main) object (for efficiency). + +=cut + +=back + +=cut + +sub send_receipt { + my $self = shift; + my $opt = ref($_[0]) ? shift : { @_ }; + + my $cust_main = $opt->{'cust_main'} || $self->cust_main; + + my $conf = new FS::Conf; + + my $msgnum = $conf->config('refund_receipt_msgnum', $cust_main->agentnum); + return "No refund_receipt_msgnum configured" unless $msgnum; + + my $msg_template = qsearchs('msg_template',{ msgnum => $msgnum}); + return "Could not load template" + unless $msg_template; + + my $cust_msg = $msg_template->prepare( + 'cust_main' => $cust_main, + 'object' => $self, + 'msgtype' => 'receipt', + ); + return 'Error preparing message' unless $cust_msg; + my $error = $cust_msg->insert; + return $error if $error; + + my $queue = new FS::queue { + 'job' => 'FS::cust_msg::process_send', + 'custnum' => $cust_main->custnum, + }; + $error = $queue->insert( $cust_msg->custmsgnum ); + + return $error; +} + =back =head1 CLASS METHODS @@ -411,6 +477,9 @@ sub _upgrade_data { # class method my ($class, %opts) = @_; $class->_upgrade_reasonnum(%opts); $class->_upgrade_otaker(%opts); + + local $ignore_empty_reasonnum = 1; + $class->upgrade_set_cardtype; } =back