summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2005-11-27 21:59:24 +0000
committerivan <ivan>2005-11-27 21:59:24 +0000
commit1fc8b74ee30a0bc8bc800713bff9ccc9983527e5 (patch)
treee5a81a925fa6b5c16b9564e6983ac78837f75737
parenta8c51f52a9a13c13b17c00e8bd8bcbafd2bc6424 (diff)
per-agent billco spools
-rw-r--r--FS/FS/cust_bill.pm59
-rwxr-xr-xhttemplate/edit/part_bill_event.cgi79
2 files changed, 71 insertions, 67 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 0cfe5c9..44b50ae 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -739,16 +739,9 @@ server
username
password
dir
-format - 'default' or 'billco'
-
-#???
-If I<format> is not specified or "default", the file will be named
-"N-YYYYMMDDHHMMSS.csv" where N is the invoice number and YYMMDDHHMMSS is a
-timestamp.
-#???
-If I<format> is "billco", two files will be created and uploaded. They will be named "N-YYYYMMDDHHMMSS-header.csv" and "N-YYYYMMDDHHMMSS-detail.csv" where N
-is the invoice number and YYMMDDHHMMSS is a timestamp(???).
+The file will be named "N-YYYYMMDDHHMMSS.csv" where N is the invoice number
+and YYMMDDHHMMSS is a timestamp.
See L</print_csv> for a description of the output format.
@@ -763,27 +756,13 @@ sub send_csv {
mkdir $spooldir, 0700 unless -d $spooldir;
my $tracctnum = $self->invnum. time2str('-%Y%m%d%H%M%S', time);
- my $file = "$spooldir/$tracctnum";
- if ( lc($opt{'format'}) eq 'billco' ) {
- $file .= '-header.csv';
- } else {
- #$file = $spooldir. '/'. $self->invnum. time2str('-%Y%m%d%H%M%S.csv', time);
- $file .= '.csv';
- }
+ my $file = "$spooldir/$tracctnum.csv";
my ( $header, $detail ) = $self->print_csv(%opt, 'tracctnum' => $tracctnum );
open(CSV, ">$file") or die "can't open $file: $!";
print CSV $header;
- my $oldfile = '';
- if ( lc($opt{'format'}) eq 'billco' ) {
- close CSV;
- $oldfile = $file;
- $file = "$spooldir/$tracctnum-detail.csv";
- open(CSV,">$file") or die "can't open $file: $!";
- }
-
print CSV $detail;
close CSV;
@@ -804,14 +783,10 @@ sub send_csv {
$net->cwd($opt{dir}) or die "can't cwd to $opt{dir}";
- if ( $oldfile) {
- $net->put($oldfile) or die "can't put $oldfile: $!";
- }
$net->put($file) or die "can't put $file: $!";
$net->quit;
- unlink $oldfile if $oldfile;
unlink $file;
}
@@ -828,6 +803,8 @@ Options are:
=item dest - if set (to POST, EMAIL or FAX), only sends spools invoices if the customer has the corresponding invoice destinations set (see L<FS::cust_main_invoice>).
+=item agent_spools - if set to a true value, will spool to per-agent files rather than a single global file
+
=back
=cut
@@ -835,26 +812,25 @@ Options are:
sub spool_csv {
my($self, %opt) = @_;
+ my $cust_main = $self->cust_main;
+
if ( $opt{'dest'} ) {
my %invoicing_list = map { /^(POST|FAX)$/ or 'EMAIL' =~ /^(.*)$/; $1 => 1 }
- $self->cust_main->invoicing_list;
+ $cust_main->invoicing_list;
return 'N/A' unless $invoicing_list{$opt{'dest'}}
|| ! keys %invoicing_list;
}
- #create file(s)
-
my $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/cust_bill";
mkdir $spooldir, 0700 unless -d $spooldir;
my $tracctnum = $self->invnum. time2str('-%Y%m%d%H%M%S', time);
- my $file = "$spooldir/spool";
- if ( lc($opt{'format'}) eq 'billco' ) {
- $file .= '-header.csv';
- } else {
- #$file = $spooldir. '/'. $self->invnum. time2str('-%Y%m%d%H%M%S.csv', time);
- $file .= '.csv';
- }
+
+ my $file =
+ "$spooldir/".
+ ( $opt{'agent_spools'} ? 'agentnum'.$cust_main->agentnum : 'spool' ).
+ ( lc($opt{'format'}) eq 'billco' ? '-header' : '' ) .
+ '.csv';
my ( $header, $detail ) = $self->print_csv(%opt, 'tracctnum' => $tracctnum );
@@ -864,14 +840,15 @@ sub spool_csv {
print CSV $header;
- my $oldfile = '';
if ( lc($opt{'format'}) eq 'billco' ) {
flock(CSV, LOCK_UN);
close CSV;
- $oldfile = $file;
- $file = "$spooldir/spool-detail.csv";
+ $file =
+ "$spooldir/".
+ ( $opt{'agent_spools'} ? 'agentnum'.$cust_main->agentnum : 'spool' ).
+ '-detail.csv';
open(CSV,">>$file") or die "can't open $file: $!";
flock(CSV, LOCK_EX);
diff --git a/httemplate/edit/part_bill_event.cgi b/httemplate/edit/part_bill_event.cgi
index 7e27bd4..64a8249 100755
--- a/httemplate/edit/part_bill_event.cgi
+++ b/httemplate/edit/part_bill_event.cgi
@@ -223,7 +223,7 @@ tie my %events, 'Tie::IxHash',
);',
'html' =>
'<TABLE BORDER=0>'.
- '<TR><TD align="right">Format ("default" or "billco"): </TD>'.
+ '<TR><TD ALIGN="right">Format ("default" or "billco"): </TD>'.
'<TD>'.
'<!--'.
'<SELECT NAME="ftpformat">'.
@@ -251,31 +251,58 @@ tie my %events, 'Tie::IxHash',
'spool_csv' => {
'name' => 'Spool CSV invoice data',
- 'code' => '$cust_bill->spool_csv( \'format\' => \'%%%spoolformat%%%\',
- \'dest\' => \'%%%spooldest%%%\',
- );',
- 'html' =>
- '<TABLE BORDER=0>'.
- '<TR><TD align="right">Format ("default" or "billco"): </TD>'.
- '<TD>'.
- '<!--'.
- '<SELECT NAME="spoolformat">'.
- '<OPTION VALUE="default">Default'.
- '<OPTION VALUE="billco">Billco'.
- '</SELECT>'.
- '-->'.
- '<INPUT TYPE="text" NAME="spoolformat" VALUE="%%%spoolformat%%%">'.
- '</TD></TR>'.
- '<TR><TD align="right">For destination: </TD>'.
- '<TD>'.
- '<SELECT NAME="spooldest">'.
- '<OPTION VALUE="">(all)'.
- '<OPTION VALUE="POST">Postal mail'.
- '<OPTION VALUE="EMAIL">Email'.
- '<OPTION VALUE="Fax">Fax'.
- '</SELECT>'.
- '</TD></TR>'.
- '</TABLE>',
+ 'code' => '$cust_bill->spool_csv(
+ \'format\' => \'%%%spoolformat%%%\',
+ \'dest\' => \'%%%spooldest%%%\',
+ \'agent_spools\' => \'%%%spoolagent_spools%%%\',
+ );',
+ 'html' => sub {
+ my $plandata = shift;
+
+ my $html =
+ '<TABLE BORDER=0>'.
+ '<TR><TD ALIGN="right">Format: </TD>'.
+ '<TD>'.
+ '<SELECT NAME="spoolformat">';
+
+ foreach my $option (qw( default billco )) {
+ $html .= qq(<OPTION VALUE="$option");
+ $html .= ' SELECTED' if $option eq $plandata->{'spoolformat'};
+ $html .= ">\u$option";
+ }
+
+ $html .=
+ '</SELECT>'.
+ '</TD></TR>'.
+ '<TR><TD ALIGN="right">For destination: </TD>'.
+ '<TD>'.
+ '<SELECT NAME="spooldest">';
+
+ tie my %dest, 'Tie::IxHash',
+ '' => '(all)',
+ 'POST' => 'Postal Mail',
+ 'EMAIL' => 'Email',
+ 'FAX' => 'Fax',
+ ;
+
+ foreach my $dest (keys %dest) {
+ $html .= qq(<OPTION VALUE="$dest");
+ $html .= ' SELECTED' if $dest eq $plandata->{'spooldest'};
+ $html .= '>'. $dest{$dest};
+ }
+
+ $html .=
+ '</SELECT>'.
+ '</TD></TR>'.
+ '<TR><TD ALIGN="right">Individual per-agent spools? </TD>'.
+ '<TD><INPUT TYPE="checkbox" NAME="spoolagent_spools" VALUE="1" '.
+ ( $plandata->{'spoolagent_spools'} ? 'CHECKED' : '' ).
+ '>'.
+ '</TD></TR>'.
+ '</TABLE>';
+
+ $html;
+ },
'weight' => 50,
},