add svc_phone on new customer first package, RT#4315
[freeside.git] / httemplate / edit / cust_main / first_pkg.html
diff --git a/httemplate/edit/cust_main/first_pkg.html b/httemplate/edit/cust_main/first_pkg.html
new file mode 100644 (file)
index 0000000..0de33c0
--- /dev/null
@@ -0,0 +1,55 @@
+% if ( @part_pkg ) {
+
+    <BR><BR>
+    <FONT SIZE="+1"><B>First package</B></FONT>
+    <% ntable("#cccccc") %>
+
+      <TR>
+        <TD COLSPAN=2>
+          <% include('first_pkg/select-part_pkg.html',
+                       'part_pkg' => \@part_pkg,
+                       %opt,
+                       # map { $_ => $opt{$_} } qw( pkgpart_svcpart saved_domsvc )
+                    )
+          %>
+
+% } 
+<%init>
+
+my( $cust_main, %opt ) = @_;
+
+# pry the wrong place for this logic.  also pretty expensive
+
+#false laziness, copied from FS::cust_pkg::order
+my $pkgpart;
+my $agentnum = '';
+my @agents = $FS::CurrentUser::CurrentUser->agents;
+if ( scalar(@agents) == 1 ) {
+  # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
+  $pkgpart = $agents[0]->pkgpart_hashref;
+  $agentnum = $agents[0]->agentnum;
+} else {
+  #can't know (agent not chosen), so, allow all
+  $agentnum = 'all';
+  my %typenum;
+  foreach my $agent ( @agents ) {
+    next if $typenum{$agent->typenum}++;
+    $pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
+  }
+}
+#eslaf
+
+my @first_svc = ( 'svc_acct', 'svc_phone' );
+
+my @part_pkg =
+  grep { $_->svcpart(\@first_svc)
+         && ( $pkgpart->{ $_->pkgpart } 
+              || $agentnum eq 'all'
+              || ( $agentnum ne 'all' && $agentnum && $_->agentnum
+                   && $_->agentnum == $agentnum
+                 )
+            )
+       }
+  qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
+
+</%init>