blob: aa0eb20825d7826bf7e3477ff2e92a48b0afe6a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
|