Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / search / pay_batch.cgi
index 34297a5..05415f3 100755 (executable)
@@ -7,11 +7,15 @@
                                       'order_by'  => 'ORDER BY batchnum DESC',
                                    },
                 'count_query'   => "$count_query $extra_sql",
+                 'agent_virt'    => 1,
+                 'agent_null_right' => 'Process batches', #'Process global batches',
+                 'agent_pos'     => 1,
                 'header'        => [ 'Batch',
                                      'Type',
                                      'First Download',
                                      'Last Upload',
-                                     'Item Count',
+                                     'Items',
+                                      'Unresolved',
                                      'Amount',
                                      'Status',
                                     ],
                                        }
                                      },
                                      sub {
-                                        my $st = "SELECT COUNT(*) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
-                                        my $sth = dbh->prepare($st)
-                                          or die dbh->errstr. "doing $st";
-                                        $sth->execute
-                                         or die "Error executing \"$st\": ". $sth->errstr;
-                                        $sth->fetchrow_arrayref->[0];
-                                     },
+                                        FS::cust_pay_batch->count(
+                                          'batchnum = '.$_[0]->batchnum
+                                        )
+                                      },
+                                      sub {
+                                        FS::cust_pay_batch->count(
+                                          'status is null and batchnum = '.
+                                            $_[0]->batchnum
+                                        )
+                                      },
                                      sub {
                                         my $st = "SELECT SUM(amount) from cust_pay_batch WHERE batchnum=" . shift->batchnum;
                                         my $sth = dbh->prepare($st)