Merge branch 'master' of https://github.com/jgoodman/Freeside
[freeside.git] / FS / FS / cust_pay.pm
index 63d7c48..10b51ad 100644 (file)
@@ -414,12 +414,17 @@ sub void {
   } );
   $cust_pay_void->reason(shift) if scalar(@_);
   my $error = $cust_pay_void->insert;
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return $error;
+
+  my $cust_pay_pending =
+    qsearchs('cust_pay_pending', { paynum => $self->paynum });
+  if ( $cust_pay_pending ) {
+    $cust_pay_pending->set('void_paynum', $self->paynum);
+    $cust_pay_pending->set('paynum', '');
+    $error ||= $cust_pay_pending->replace;
   }
 
-  $error = $self->delete;
+  $error ||= $self->delete;
+
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
     return $error;
@@ -611,11 +616,12 @@ sub send_receipt {
         'custnum' => $cust_main->custnum,
       };
       $error = $queue->insert(
-         FS::msg_template->by_key($msgnum)->prepare(
+        FS::msg_template->by_key($msgnum)->prepare(
           'cust_main'   => $cust_main,
           'object'      => $self,
           'from_config' => 'payment_receipt_from',
-        )
+        ),
+        'msgtype' => 'receipt', # override msg_template's default
       );
 
     } elsif ( $conf->exists('payment_receipt_email') ) {
@@ -658,6 +664,7 @@ sub send_receipt {
         'job'     => 'FS::Misc::process_send_generated_email',
         'paynum'  => $self->paynum,
         'custnum' => $cust_main->custnum,
+        'msgtype' => 'receipt',
       };
       $error = $queue->insert(
         'from'    => $conf->config('invoice_from', $cust_main->agentnum),