Merge branch 'master' of git.freeside.biz:/home/git/freeside
authorIvan Kohler <ivan@freeside.biz>
Wed, 28 Jan 2015 10:26:52 +0000 (02:26 -0800)
committerIvan Kohler <ivan@freeside.biz>
Wed, 28 Jan 2015 10:26:52 +0000 (02:26 -0800)
1  2 
FS/FS/Conf.pm
FS/FS/cust_main.pm
FS/FS/cust_pay.pm

diff --combined FS/FS/Conf.pm
@@@ -773,7 -773,7 +773,7 @@@ sub reason_type_options 
    {
      'key'         => 'log_sent_mail',
      'section'     => 'notification',
 -    'description' => 'Enable logging of template-generated email.',
 +    'description' => 'Enable logging of all sent email.',
      'type'        => 'checkbox',
    },
  
    {
      'key'         => 'invoice_from',
      'section'     => 'required',
-     'description' => 'Return address on email invoices',
+     'description' => 'Return address on email invoices (address only, see invoice_from_name)',
      'type'        => 'text',
      'per_agent'   => 1,
+     'validate'    => sub { $_[0] =~
+                              /^[^@]+\@[[:alnum:]-]+(\.[[:alnum:]-]+)+$/
+                              ? '' : 'Invalid email address';
+                          }
+   },
+   {
+     'key'         => 'invoice_from_name',
+     'section'     => 'invoicing',
+     'description' => 'Return name on email invoices (set address in invoice_from)',
+     'type'        => 'text',
+     'per_agent'   => 1,
+     'validate'    => sub { (($_[0] =~ /[^[:alnum:][:space:]]/) && ($_[0] !~ /^\".*\"$/))
+                            ? 'Invalid name.  Use quotation marks around names that contain punctuation.'
+                            : '' }
    },
  
    {
diff --combined FS/FS/cust_main.pm
@@@ -2139,8 -2139,8 +2139,8 @@@ Returns all notes (see L<FS::cust_main_
  
  sub notes {
    my($self,$orderby_classnum) = (shift,shift);
 -  my $orderby = "_DATE DESC";
 -  $orderby = "CLASSNUM ASC, $orderby" if $orderby_classnum;
 +  my $orderby = "sticky DESC, _date DESC";
 +  $orderby = "classnum ASC, $orderby" if $orderby_classnum;
    qsearch( 'cust_main_note',
             { 'custnum' => $self->custnum },
             '',
@@@ -4327,7 -4327,10 +4327,10 @@@ sub notify 
  
    return unless $conf->exists($template);
  
-   my $from = $conf->config('invoice_from', $self->agentnum)
+   my $from = $conf->config('invoice_from_name', $self->agentnum) ?
+              $conf->config('invoice_from_name', $self->agentnum) . ' <' .
+              $conf->config('invoice_from', $self->agentnum) . '>' :
+              $conf->config('invoice_from', $self->agentnum)
      if $conf->exists('invoice_from', $self->agentnum);
    $from = $options{from} if exists($options{from});
  
diff --combined FS/FS/cust_pay.pm
@@@ -694,7 -694,10 +694,10 @@@ sub send_receipt 
          'msgtype' => 'receipt',
        };
        $error = $queue->insert(
-         'from'    => $conf->config('invoice_from', $cust_main->agentnum),
+         'from'    => $conf->config('invoice_from_name', $cust_main->agentnum ) ?
+                      $conf->config('invoice_from_name', $cust_main->agentnum ) . ' <' .
+                      $conf->config('invoice_from', $cust_main->agentnum ) . '>' :
+                      $conf->config('invoice_from', $cust_main->agentnum ),
                                     #invoice_from??? well as good as any
          'to'      => \@invoicing_list,
          'subject' => 'Payment receipt',
@@@ -942,11 -945,10 +945,11 @@@ sub _upgrade_data {  #class metho
  
      #not the most efficient, but hey, it only has to run once
  
 -    my $where = "WHERE ( otaker IS NULL OR otaker = '' OR otaker = 'ivan' ) ".
 -                "  AND usernum IS NULL ".
 -                "  AND 0 < ( SELECT COUNT(*) FROM cust_main                 ".
 -                "              WHERE cust_main.custnum = cust_pay.custnum ) ";
 +    my $where = " WHERE ( otaker IS NULL OR otaker = '' OR otaker = 'ivan' )
 +                    AND usernum IS NULL
 +                    AND EXISTS ( SELECT 1 FROM cust_main                    
 +                                   WHERE cust_main.custnum = cust_pay.custnum )
 +                ";
  
      my $count_sql = "SELECT COUNT(*) FROM cust_pay $where";