1 package FS::part_export::indosoft_pbx;
2 use base qw( FS::part_export );
6 use Lingua::EN::NameParse;
8 tie my %options, 'Tie::IxHash',
9 'host' => { label => 'Q-Suite API hostname' },
10 'gateway_key' => { label => 'API gateway key' },
14 'svc' => [qw( svc_pbx svc_phone svc_acct )],
16 'Export PBX tenants and DIDs to Indosoft Q-Suite',
17 'options' => \%options,
20 Export PBX tenants and DIDs to Indosoft Q-Suite.
21 Net::Indosoft::QSuite is required.
27 sub rebless { shift; }
30 my($self, $svc_x) = (shift, shift);
32 my $cust_main = $svc_x->cust_svc->cust_pkg->cust_main;
34 if ( $svc_x->isa('FS::svc_pbx') ) {
36 my $uuid = $self->indosoft_runcommand( 'editTenant',
38 'name' => $svc_x->title || $cust_main->name,
39 'shortname' => $svc_x->svcnum, #?
40 #'hostname' => #XXX what goes here? add to svc_pbx?
41 'callerid_name' => $svc_x->title || $cust_main->name, #separate? add to svc_pbx?
42 #'callerid_number' => #XXX where tf to get this from? svc_pbx again?
48 #my $unneeded_trunk_uuid = $self->indosoft_command( 'assignTrunkToTenant,
49 # 'tenant_uuid' => $uuid,
50 # 'trunk_id' => $self->option('trunk_id'),
53 } elsif ( $svc_x->isa('FS::svc_phone') ) {
55 my $same_number = $self->indosoft_runcommand( 'editDID',
57 'tenant_uuid' => $svc_x->svc_pbx->id,
58 'number' => $svc_x->phonenum,
59 # 'auto_attendant_uuid' =>#XXX where to get this from? svc_phone.newfield?
62 #set the auto-attendant name, repeate limit, response limit, extension dialing?
66 } elsif ( $svc_x->isa('FS::svc_acct') ) {
68 my($firstname, $lastname);
69 my $NameParse = new Lingua::EN::NameParse;
70 if ( $NameParse->parse( $svc_x->finger ) ) {
71 $firstname = $cust_main->first,
72 $lastname = $cust_main->get('last'),
74 my %name = $NameParse->components;
75 $firstname = $name{given_name_1} || $name{initials_1}; #wtf NameParse, Ed?
76 $lastname = $name{surname_1};
79 my $uuid = $self->indosoft_command( 'editEmployee',
81 'tenant_uuid' => $svc_x->svc_pbx->id,
82 'username' => $svc_x->username,
83 'password' => $svc_x->_password,
84 'firstname' => $firstname,
85 'lastname' => $firstname,
88 #XXX extensions (pbx_extension export? look at how svc_phone does its device export stuff
90 #XXX devices (links employee to extension (svc_acct to pbx_extension)? how's that? seems like they _go_ with extensions. where to pick user?
93 #XXX extension forwarding?
96 die "guru meditation #five five five five: $svc_x is not FS::svc_pbx, FS::svc_phone or FS::svc_acct";
99 local($insert_hack) = 1;
100 #my $error = $svc_phone->replace;
101 #return $error if $error;
106 sub _export_replace {
107 my( $self, $new, $old ) = (shift, shift, shift);
109 return '' if $insert_hack;
115 my( $self, $svc_phone ) = (shift, shift);
123 # #these three are optional
124 # # fallback for svc_acct will change and restore password
125 # sub _export_suspend {
126 # my( $self, $svc_phone ) = (shift, shift);
127 # $err_or_queue = $self->indosoft_queue( $svc_phone->svcnum,
128 # 'suspend', $svc_phone->username );
129 # ref($err_or_queue) ? '' : $err_or_queue;
132 # sub _export_unsuspend {
133 # my( $self, $svc_phone ) = (shift, shift);
134 # $err_or_queue = $self->indosoft_queue( $svc_phone->svcnum,
135 # 'unsuspend', $svc_phone->username );
136 # ref($err_or_queue) ? '' : $err_or_queue;
140 # my($self, $svc_phone, $arrayref) = (shift, shift, shift);
141 # #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_phone->username.
142 # # qq!">!. $svc_phone->username. qq!</A>!;
148 sub indosoft_runcommand {
149 my( $self, $method ) = (shift, shift);
152 $self->option('host'),
153 $self->option('gateway_key'),
160 sub indosoft_command {
161 my( $host, $gateway_key, $method, @args ) = @_;
163 eval 'use Net::Indosoft::Qsuite;';
166 my $qsuite = new Net::Indosoft::Qsuite( 'host' => $host,
167 'gateway_key' => $gateway_key,
170 my $return = $qsuite->$method( @args );
172 die "Indosoft error: ". $qsuite->errstr if $qsuite->errstr;
179 # #a good idea to queue anything that could fail or take any time
180 # sub indosoft_queue {
181 # my( $self, $svcnum, $method ) = (shift, shift, shift);
182 # my $queue = new FS::queue {
183 # 'svcnum' => $svcnum,
184 # 'job' => "FS::part_export::indosoft::indosoft_$method",
186 # $queue->insert( @_ ) or $queue;
189 # sub indosoft_insert { #subroutine, not method
190 # my( $username, $password ) = @_;
191 # #do things with $username and $password
194 # sub indosoft_replace { #subroutine, not method
197 # sub indosoft_delete { #subroutine, not method
198 # my( $username ) = @_;
199 # #do things with $username
202 # sub indosoft_suspend { #subroutine, not method
205 # sub indosoft_unsuspend { #subroutine, not method