[freeside-commits] freeside/httemplate/edit/process cust_main.cgi, 1.38, 1.39

Ivan,,, ivan at wavetail.420.am
Sat Apr 11 23:09:14 PDT 2009


Update of /home/cvs/cvsroot/freeside/httemplate/edit/process
In directory wavetail.420.am:/tmp/cvs-serv9781/httemplate/edit/process

Modified Files:
	cust_main.cgi 
Log Message:
add svc_phone on new customer first package, RT#4315

Index: cust_main.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/edit/process/cust_main.cgi,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- cust_main.cgi	17 Jun 2008 01:43:59 -0000	1.38
+++ cust_main.cgi	12 Apr 2009 06:09:12 -0000	1.39
@@ -27,8 +27,7 @@
 
 $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
 
-#my $payby = $cgi->param('payby');
-my $payby = $cgi->param('select'); # XXX key
+my $payby = $cgi->param('payby');
 
 my %noauto = (
   'CARD' => 'DCRD',
@@ -37,8 +36,6 @@
 $payby = $noauto{$payby}
   if ! $cgi->param('payauto') && exists $noauto{$payby};
 
-$cgi->param('payby', $payby);
-
 if ( $payby ) {
   if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
     $cgi->param('payinfo',
@@ -93,34 +90,39 @@
   if $cgi->param('paid');
 
 #perhaps this stuff should go to cust_main.pm
-my $cust_pkg = '';
-my $svc_acct = '';
 if ( $new->custnum eq '' ) {
 
+  my $cust_pkg = '';
+  my $svc;
+
   if ( $cgi->param('pkgpart_svcpart') ) {
+
     my $x = $cgi->param('pkgpart_svcpart');
     $x =~ /^(\d+)_(\d+)$/ or die "illegal pkgpart_svcpart $x\n";
     my($pkgpart, $svcpart) = ($1, $2);
+    my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } );
     #false laziness: copied from FS::cust_pkg::order (which should become a
     #FS::cust_main method)
     my(%part_pkg);
     # generate %part_pkg
     # $part_pkg{$pkgpart} is true iff $custnum may purchase $pkgpart
     my $agent = qsearchs('agent',{'agentnum'=> $new->agentnum });
-    	#my($type_pkgs);
-    	#foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
-    	#  my($pkgpart)=$type_pkgs->pkgpart;
-    	#  $part_pkg{$pkgpart}++;
-    	#}
-    # $pkgpart_href->{PKGPART} is true iff $custnum may purchase $pkgpart
-    my $pkgpart_href = $agent->pkgpart_hashref;
-    #eslaf
 
-    # this should wind up in FS::cust_pkg!
-    $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum. ") can't ".
-               "purchase pkgpart ". $pkgpart
-      #unless $part_pkg{ $pkgpart };
-      unless $pkgpart_href->{ $pkgpart };
+    if ( $agent ) {
+      # $pkgpart_href->{PKGPART} is true iff $custnum may purchase $pkgpart
+      my $pkgpart_href = $agent->pkgpart_hashref
+        if $agent;
+      #eslaf
+
+      # this should wind up in FS::cust_pkg!
+      $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum.
+                 ") can't purchase pkgpart ". $pkgpart
+        #unless $part_pkg{ $pkgpart };
+        unless $pkgpart_href->{ $pkgpart }
+            || $agent->agentnum == $part_pkg->agentnum;
+    } else {
+      $error = 'Select agent';
+    }
 
     $cust_pkg = new FS::cust_pkg ( {
       #later         'custnum' => $custnum,
@@ -132,32 +134,49 @@
 
     #$error ||= $cust_svc->check;
 
-    my %svc_acct = (
-                     'svcpart'   => $svcpart,
-                     'username'  => $cgi->param('username'),
-                     '_password' => $cgi->param('_password'),
-                     'popnum'    => $cgi->param('popnum'),
-                   );
-    $svc_acct{'domsvc'} = $cgi->param('domsvc')
-      if $cgi->param('domsvc');
+    my $part_svc = qsearchs('part_svc', { 'svcpart' => $svcpart } );
+    my $svcdb = $part_svc->svcdb;
 
-    $svc_acct = new FS::svc_acct \%svc_acct;
+    if ( $svcdb eq 'svc_acct' ) {
 
-    #and just in case you were silly
-    $svc_acct->svcpart($svcpart);
-    $svc_acct->username($cgi->param('username'));
-    $svc_acct->_password($cgi->param('_password'));
-    $svc_acct->popnum($cgi->param('popnum'));
+      my %svc_acct = (
+                       'svcpart'   => $svcpart,
+                       'username'  => scalar($cgi->param('username')),
+                       '_password' => scalar($cgi->param('_password')),
+                       'popnum'    => scalar($cgi->param('popnum')),
+                     );
+      $svc_acct{'domsvc'} = $cgi->param('domsvc')
+        if $cgi->param('domsvc');
+
+      $svc = new FS::svc_acct \%svc_acct;
+
+      #and just in case you were silly
+      $svc->svcpart($svcpart);
+      $svc->username($cgi->param('username'));
+      $svc->_password($cgi->param('_password'));
+      $svc->popnum($cgi->param('popnum'));
+
+    } elsif ( $svcdb eq 'svc_phone' ) {
+
+      my %svc_phone = (
+                        'svcpart' => $svcpart,
+                        map { $_ => scalar($cgi->param($_)) }
+                          qw( countrycode phonenum sip_password pin phone_name )
+                      );
+
+      $svc = new FS::svc_phone \%svc_phone;
+
+    } else {
+      die "$svcdb not handled on new customer yet";
+    }
 
     #$error ||= $svc_acct->check;
 
-  } elsif ( $cgi->param('username') ) { #good thing to catch
-    $error = "Can't assign username without a package!";
   }
 
   use Tie::RefHash;
   tie my %hash, 'Tie::RefHash';
-  %hash = ( $cust_pkg => [ $svc_acct ] ) if $cust_pkg;
+  %hash = ( $cust_pkg => [ $svc ] ) if $cust_pkg;
   $error ||= $new->insert( \%hash, \@invoicing_list );
 
   my $conf = new FS::Conf;



More information about the freeside-commits mailing list