default service location is cust_main ship_ address when present! RT#4499
[freeside.git] / httemplate / view / cust_main / packages / location.html
index 0f58b36..b51616d 100644 (file)
@@ -4,32 +4,60 @@
   <I><FONT SIZE=-1>(default service address)</FONT><BR>
 % }
 
-  <% $loc->address1 |h %><BR>
+  <% $loc->get($prefix.'address1') |h %><BR>
 
-% if ( $loc->address2 !~ /^\s*$/ ) {
-    <% $loc->address2 |h %><BR>
+% if ( $loc->get($prefix.'address2') !~ /^\s*$/ ) {
+    <% $loc->get($prefix.'address2') |h %><BR>
 % }
 
-  <% $loc->city |h %><% $loc->county ? ' ('.$loc->county.' county)' : '' |h %>,
-  <% $loc->state |h %> &nbsp; <% $loc->zip |h %><BR>
+  <% $loc->get($prefix.'city') |h %><% $loc->get($prefix.'county') ? ' ('.$loc->get($prefix.'county').' county)' : '' |h %>,
+  <% $loc->get($prefix.'state') |h %> &nbsp; <% $loc->get($prefix.'zip') |h %><BR>
 
-% if ( $loc->country ne $countrydefault ) {
-  <% code2country( $loc->country ) %>
+% if ( $loc->get($prefix.'country') ne $countrydefault ) {
+  <% code2country( $loc->get($prefix.'country') ) %>
 % }
 
   </I>
 
+% if ( ! $cust_pkg->get('cancel')
+%      && $FS::CurrentUser::CurrentUser->access_right('Change customer package')
+%    )
+% {
+  <FONT SIZE=-1>
+    (&nbsp;<%pkg_change_location_link($cust_pkg)%>&nbsp;)
+  </FONT>
+% } 
+
 </TD>
 <%init>
 
 my %opt = @_;
 
+my $conf = new FS::Conf;
+
 my $bgcolor        = $opt{'bgcolor'};
 my $cust_pkg       = $opt{'cust_pkg'};
 my $part_pkg       = $opt{'part_pkg'};
 my $conf           = new FS::Conf;
 my $countrydefault = $conf->config('countrydefault') || 'US';
+my $statedefault   = $conf->config('statedefault')
+                     || ($countrydefault eq 'US' ? 'CA' : '');
 
 my $loc = $cust_pkg->cust_location_or_main;
+my $prefix =
+  ( $loc->table eq 'cust_main' && length($loc->ship_last) ) ? 'ship_' : ''; #doh
+
+sub pkg_change_location_link {
+  my $cust_pkg = shift;
+  my $pkgpart = $cust_pkg->pkgpart;
+  include( '/elements/popup_link-cust_pkg.html',
+    'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
+                     "address1=;address2=;city=;county=;state=$statedefault;".
+                     "zip=;country=$countrydefault",
+    'label'       => 'Change&nbsp;location',
+    'actionlabel' => 'Change',
+    'cust_pkg'    => $cust_pkg,
+  );
+}
 
 </%init>