Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into FREESIDE...
authorJonathan Prykop <jonathan@freeside.biz>
Thu, 12 Feb 2015 19:30:03 +0000 (13:30 -0600)
committerJonathan Prykop <jonathan@freeside.biz>
Thu, 12 Feb 2015 19:30:03 +0000 (13:30 -0600)
FS/FS/ClientAPI/MyAccount.pm
FS/FS/cust_location.pm
FS/FS/cust_main/Packages.pm
FS/FS/quotation_pkg.pm
FS/FS/quotation_pkg_discount.pm
fs_selfservice/FS-SelfService/SelfService.pm
httemplate/edit/process/elements/process.html
httemplate/elements/tr-select-inventory_item.html

index 279acb2..023c1d6 100644 (file)
@@ -46,8 +46,9 @@ use FS::payby;
 use FS::acct_rt_transaction;
 use FS::msg_template;
 use FS::contact;
+use FS::cust_location;
 
-$DEBUG = 1;
+$DEBUG = 0;
 $me = '[FS::ClientAPI::MyAccount]';
 
 use vars qw( @cust_main_editable_fields @location_editable_fields );
@@ -2268,11 +2269,23 @@ sub order_pkg {
     or return { 'error' => "unknown custnum $custnum" };
 
   my $status = $cust_main->status;
+
+  my %order_pkg_options = ());
+  if ( $p->{locationnum} > 0 ) {
+    $order_pkg_options{locationnum} = delete($p->{locationnum});
+  } elsif ( $p->{address1} ) {
+    $order_pkg_options{'cust_location'} = new FS::cust_location {
+      map { $_ => $p->{$_} }
+        qw( address1 address2 city county state zip country )
+    };
+  }
+
   #false laziness w/ClientAPI/Signup.pm
 
   my $cust_pkg = new FS::cust_pkg ( {
-    'custnum' => $custnum,
-    'pkgpart' => $p->{'pkgpart'},
+    'custnum'  => $custnum,
+    'pkgpart'  => $p->{'pkgpart'},
+    'quantity' => $p->{'quantity'} || 1,
   } );
   my $error = $cust_pkg->check;
   return { 'error' => $error } if $error;
@@ -2331,11 +2344,12 @@ sub order_pkg {
 
   }
 
-  use Tie::RefHash;
-  tie my %hash, 'Tie::RefHash';
-  %hash = ( $cust_pkg => \@svc );
-  #msgcat
-  $error = $cust_main->order_pkgs( \%hash, 'noexport' => 1 );
+  $error = $cust_main->order_pkg(
+    'cust_pkg' => $cust_pkg,
+    'svcs'     => \@svc,
+    'noexport' => 1,
+    %order_pkg_options,
+  );
   return { 'error' => $error } if $error;
 
   my $conf = new FS::Conf;
index 23dbce9..ad6d706 100644 (file)
@@ -322,7 +322,7 @@ sub check {
     $self->ut_numbern('locationnum')
     || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
     || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
-    || $self->ut_alphan('locationname')
+    || $self->ut_textn('locationname')
     || $self->ut_text('address1')
     || $self->ut_textn('address2')
     || $self->ut_text('city')
index 7bb3272..19ee63a 100644 (file)
@@ -59,6 +59,15 @@ jobs will have a dependancy on the supplied job (they will not run until the
 specific job completes).  This can be used to defer provisioning until some
 action completes (such as running the customer's credit card successfully).
 
+=item noexport
+
+This option is option is deprecated but still works for now (use
+I<depend_jobnum> instead for new code).  If I<noexport> is set true, no
+provisioning jobs (exports) are scheduled.  (You can schedule them later with
+the B<reexport> method for each cust_pkg object.  Using the B<reexport> method
+on the cust_main object is not recommended, as existing services will also be
+reexported.)
+
 =item ticket_subject
 
 Optional subject for a ticket created and attached to this customer
@@ -81,6 +90,8 @@ sub order_pkg {
        join(', ', map { "$_: $opt->{$_}" } keys %$opt ). "\n"
     if $DEBUG;
 
+  local $FS::svc_Common::noexport_hack = 1 if $opt->{'noexport'};
+
   my $cust_pkg = $opt->{'cust_pkg'};
   my $svcs     = $opt->{'svcs'} || [];
 
@@ -184,18 +195,14 @@ sub order_pkg {
         'custnum'       => $self->custnum,
         'main_pkgnum'   => $cust_pkg->pkgnum,
         # try to prevent as many surprises as possible
-        'pkgbatch'      => $cust_pkg->pkgbatch,
-        'start_date'    => $cust_pkg->start_date,
-        'order_date'    => $cust_pkg->order_date,
-        'expire'        => $cust_pkg->expire,
-        'adjourn'       => $cust_pkg->adjourn,
-        'contract_end'  => $cust_pkg->contract_end,
-        'refnum'        => $cust_pkg->refnum,
-        'discountnum'   => $cust_pkg->discountnum,
-        'waive_setup'   => $cust_pkg->waive_setup,
         'allow_pkgpart' => $opt->{'allow_pkgpart'},
+        map { $_ => $cust_pkg->$_() }
+          qw( pkgbatch
+              start_date order_date expire adjourn contract_end
+              refnum discountnum waive_setup
+            )
     });
-    $error = $self->order_pkg('cust_pkg' => $pkg,
+    $error = $self->order_pkg('cust_pkg'    => $pkg,
                               'locationnum' => $cust_pkg->locationnum);
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
@@ -235,7 +242,8 @@ on the supplied jobnum (they will not run until the specific job completes).
 This can be used to defer provisioning until some action completes (such
 as running the customer's credit card successfully).
 
-The I<noexport> option is deprecated.  If I<noexport> is set true, no
+The I<noexport> option is deprecated but still works for now (use
+I<depend_jobnum> instead for new code).  If I<noexport> is set true, no
 provisioning jobs (exports) are scheduled.  (You can schedule them later with
 the B<reexport> method for each cust_pkg object.  Using the B<reexport> method
 on the cust_main object is not recommended, as existing services will also be
index 88147bc..6c8aa46 100644 (file)
@@ -105,11 +105,8 @@ otherwise returns false.
 
 =cut
 
-use Data::Dumper; #XXX DEBUG
 sub insert {
   my ($self, %options) = @_;
-  warn Dumper($self);
-  warn Dumper(\%options);
 
   my $dbh = dbh;
   my $oldAutoCommit = $FS::UID::AutoCommit;
@@ -318,7 +315,7 @@ sub insert_discount {
   #my ($self, %options) = @_;
   my $self = shift;
 
-  my $cust_pkg_discount = FS::quotation_pkg_discount->new( {
+  my $quotation_pkg_discount = FS::quotation_pkg_discount->new( {
     'quotationpkgnum' => $self->quotationpkgnum,
     'discountnum'     => $self->discountnum,
     #for the create a new discount case
@@ -329,7 +326,7 @@ sub insert_discount {
     'setup'       => $self->discountnum_setup,
   } );
 
-  $cust_pkg_discount->insert;
+  $quotation_pkg_discount->insert;
 }
 
 sub _item_discount {
@@ -351,7 +348,7 @@ sub _item_discount {
     push @ext, $pkg_discount->description;
     $d->{setup_amount} -= $pkg_discount->setup_amount;
     $d->{recur_amount} -= $pkg_discount->recur_amount;
-  } 
+  }
   $d->{setup_amount} *= $self->quantity || 1;
   $d->{recur_amount} *= $self->quantity || 1;
   $d->{amount} = $d->{setup_amount} + $d->{recur_amount};
index 19a7bce..87ac6bd 100644 (file)
@@ -118,18 +118,6 @@ sub check {
 
 =back
 
-=item amount
-
-Returns the total amount of this discount (setup + recur), for compatibility
-with L<FS::cust_bill_pkg_discount>.
-
-=cut
-
-sub amount {
-  my $self = shift;
-  return $self->get('setup_amount') + $self->get('recur_amount');
-}
-
 =item description
 
 Returns a string describing the discount (for use on the quotation).
index 8227e57..adbf32f 100644 (file)
@@ -832,6 +832,25 @@ Session identifier
 
 Package to order (see L<FS::part_pkg>).
 
+=item quantity
+
+Quantity for this package order (default 1).
+
+=item locationnum
+
+Optional locationnum for this package order, for existing locations.
+
+Or, for new locations, pass the following fields: address1*, address2, city*,
+county, state*, zip*, country.  (* = required in this case)
+
+=item address1
+
+=item address 2
+
+=item city
+
+=item 
+
 =item svcpart
 
 Service to order (see L<FS::part_svc>).
index 698540b..5b79c21 100644 (file)
@@ -219,7 +219,7 @@ my %hash =
 my @values = ( 1 );
 if ( $bfield ) {
   @values = $cgi->param($bfield);
-  warn join(',', @values);
+  #warn join(',', @values);
 }
 
 my @uploaded_files;
@@ -308,7 +308,7 @@ foreach my $value ( @values ) {
       warn "$me processing m2m:\n". Dumper( %$process_m2m )
         if $opt{'debug'};
 
-      $error = $new->process_m2m( %$process_m2m );
+      $error ||= $new->process_m2m( %$process_m2m );
     }
 
   }
@@ -350,7 +350,7 @@ foreach my $value ( @values ) {
                                                );
       }
 
-      $error = $new->process_o2m( %{ $process_o2m },
+      $error ||= $new->process_o2m( %{ $process_o2m },
                                      'params' => scalar($cgi->Vars),
                                    );
     }
index 669e85f..d7a14ec 100644 (file)
@@ -12,7 +12,6 @@
 <& tr-td-label.html, %opt &>
 <TD>
 <& select-tiered.html,
-  'prefix' => $opt{'field'}.'_',
   'tiers' => [
     {
       field         => $opt{'field'}.'_classnum',
     },
   ],
   %opt,
+  'prefix' => $opt{'prefix'}. $opt{'field'}. '_', #after %opt so it overrides
 &>
 </TD>
 </TR>
 % }
 <%init>
+
 my %opt = @_;
+
 my @classnums;
 if (ref($opt{'classnum'})) {
   @classnums = @{ $opt{'classnum'} };
@@ -45,4 +47,5 @@ if (ref($opt{'classnum'})) {
   @classnums = split(',', $opt{'classnum'});
 }
 my $classnum_sql = 'classnum IN('.join(',', @classnums).')';
+
 </%init>