summaryrefslogtreecommitdiff
path: root/FS/FS/Maestro.pm
diff options
context:
space:
mode:
authorivan <ivan>2010-09-20 21:13:16 +0000
committerivan <ivan>2010-09-20 21:13:16 +0000
commit645f747ad9e9277e6095a5f1d62bf864df56c90f (patch)
treeb11357b2969ae4878f6b69d0983bfb7f1a29fb68 /FS/FS/Maestro.pm
parentda122d33411802d26d34033a1ca68cae29125259 (diff)
Maestro.order_pkg API
Diffstat (limited to 'FS/FS/Maestro.pm')
-rw-r--r--FS/FS/Maestro.pm102
1 files changed, 102 insertions, 0 deletions
diff --git a/FS/FS/Maestro.pm b/FS/FS/Maestro.pm
index c1d047032..fc86ba3bc 100644
--- a/FS/FS/Maestro.pm
+++ b/FS/FS/Maestro.pm
@@ -1,9 +1,12 @@
package FS::Maestro;
+use strict;
use Date::Format;
use FS::Conf;
use FS::Record qw( qsearchs );
use FS::cust_main;
+use FS::cust_pkg;
+use FS::part_svc;
sub customer_status {
my( $custnum ) = shift; #@_;
@@ -138,4 +141,103 @@ sub customer_status {
}
+#some false laziness w/ MyAccount order_pkg
+sub order_pkg {
+ my $opt = ref($_[0]) ? shift : { @_ };
+
+ $opt->{'title'} = delete $opt->{'name'}
+ if !exists($opt->{'title'}) && exists($opt->{'name'});
+
+ my $custnum = $opt->{'custnum'};
+
+ my $curuser = $FS::CurrentUser::CurrentUser;
+
+ my $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => { 'custnum' => $custnum },
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+ })
+ or return { 'error' => "custnum $custnum not found" };
+
+ my $status = $cust_main->status;
+ #false laziness w/ClientAPI/Signup.pm
+
+ my $cust_pkg = new FS::cust_pkg ( {
+ 'custnum' => $custnum,
+ 'pkgpart' => $opt->{'pkgpart'},
+ } );
+ my $error = $cust_pkg->check;
+ return { 'error' => $error } if $error;
+
+ my @svc = ();
+ unless ( $opt->{'svcpart'} eq 'none' ) {
+
+ my $svcpart = '';
+ if ( $opt->{'svcpart'} =~ /^(\d+)$/ ) {
+ $svcpart = $1;
+ } else {
+ $svcpart = $cust_pkg->part_pkg->svcpart; #($svcdb);
+ }
+
+ my $part_svc = qsearchs('part_svc', { 'svcpart' => $svcpart } );
+ return { 'error' => "Unknown svcpart $svcpart" } unless $part_svc;
+
+ my $svcdb = $part_svc->svcdb;
+
+ my %fields = (
+ 'svc_acct' => [ qw( username domsvc _password sec_phrase popnum ) ],
+ 'svc_domain' => [ qw( domain ) ],
+ 'svc_phone' => [ qw( phonenum pin sip_password phone_name ) ],
+ 'svc_external' => [ qw( id title ) ],
+ 'svc_pbx' => [ qw( id title ) ],
+ );
+
+ my $svc_x = "FS::$svcdb"->new( {
+ 'svcpart' => $svcpart,
+ map { $_ => $opt->{$_} } @{$fields{$svcdb}}
+ } );
+
+ #snarf processing not necessary here (or probably at all, anymore)
+
+ my $y = $svc_x->setdefault; # arguably should be in new method
+ return { 'error' => $y } if $y && !ref($y);
+
+ $error = $svc_x->check;
+ return { 'error' => $error } if $error;
+
+ push @svc, $svc_x;
+
+ }
+
+ use Tie::RefHash;
+ tie my %hash, 'Tie::RefHash';
+ %hash = ( $cust_pkg => \@svc );
+ #msgcat
+ $error = $cust_main->order_pkgs( \%hash, '', 'noexport' => 1 );
+ return { 'error' => $error } if $error;
+
+# currently they're using this in the reseller scenario, so don't
+# bill the package immediately
+# my $conf = new FS::Conf;
+# if ( $conf->exists('signup_server-realtime') ) {
+#
+# my $bill_error = _do_bop_realtime( $cust_main, $status );
+#
+# if ($bill_error) {
+# $cust_pkg->cancel('quiet'=>1);
+# return $bill_error;
+# } else {
+# $cust_pkg->reexport;
+# }
+#
+# } else {
+ $cust_pkg->reexport;
+# }
+
+ my $svcnum = $svc[0] ? $svc[0]->svcnum : '';
+
+ return { error=>'', pkgnum=>$cust_pkg->pkgnum, svcnum=>$svcnum };
+
+}
+
1;