summaryrefslogtreecommitdiff
path: root/bin/svc_phone.export
diff options
context:
space:
mode:
Diffstat (limited to 'bin/svc_phone.export')
-rwxr-xr-xbin/svc_phone.export55
1 files changed, 55 insertions, 0 deletions
diff --git a/bin/svc_phone.export b/bin/svc_phone.export
new file mode 100755
index 000000000..aa0eb2082
--- /dev/null
+++ b/bin/svc_phone.export
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+use strict;
+use Text::CSV_XS;
+use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch);
+use FS::svc_phone;
+
+my @fields = (
+ { 'header' => 'pkgnum',
+ 'callback' => sub { shift->cust_svc->pkgnum; },
+ },
+ { 'header' => 'svcpart',
+ 'callback' => sub { shift->cust_svc->svcpart; },
+ },
+ { 'header' => 'Service',
+ 'callback' => sub { shift->cust_svc->part_svc->svc; },
+ },
+ qw(
+ phonenum
+ pin
+ sip_password
+ phone_name
+ )
+);
+
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+my $agentnum = shift or die &usage;
+
+my $csv = new Text::CSV_XS;
+
+$csv->combine( map { ref($_) ? $_->{'header'} : $_ } @fields ) or die;
+print $csv->string."\n";
+
+my @svc_phone = qsearch({
+ 'table' => 'svc_phone',
+ 'addl_from' => 'LEFT JOIN cust_svc USING (svcnum)
+ LEFT JOIN cust_pkg USING (pkgnum)
+ LEFT JOIN cust_main USING ( custnum )',
+ 'hashref' => {},
+ 'extra_sql' => "WHERE cust_main.agentnum = $agentnum",
+});
+
+foreach my $svc_phone ( @svc_phone ) {
+ $csv->combine( map { ref($_) ? &{$_->{'callback'}}($svc_phone)
+ : $svc_phone->$_()
+ }
+ @fields
+ ) or die;
+ print $csv->string."\n";
+}
+
+1;