fix UI for package editing w/recur_show_zero, add setup_show_zero, RT#9777
[freeside.git] / FS / FS / cust_pkg.pm
index c183a49..07b71dc 100644 (file)
@@ -30,6 +30,7 @@ use FS::reason;
 use FS::cust_pkg_discount;
 use FS::discount;
 use FS::UI::Web;
+use Data::Dumper;
 
 # need to 'use' these instead of 'require' in sub { cancel, suspend, unsuspend,
 # setup }
@@ -194,6 +195,8 @@ Previous pkgpart
 
 Previous locationnum
 
+=item waive_setup
+
 =back
 
 Note: setup, last_bill, bill, adjourn, susp, expire, cancel and change_date
@@ -593,10 +596,18 @@ sub check {
     || $self->ut_numbern('cancel')
     || $self->ut_numbern('adjourn')
     || $self->ut_numbern('expire')
+    || $self->ut_numbern('dundate')
     || $self->ut_enum('no_auto', [ '', 'Y' ])
+    || $self->ut_enum('waive_setup', [ '', 'Y' ])
+    || $self->ut_numbern('agent_pkgid')
+    || $self->ut_enum('recur_show_zero', [ '', 'Y', 'N', ])
+    || $self->ut_enum('setup_show_zero', [ '', 'Y', 'N', ])
   ;
   return $error if $error;
 
+  return "A package with both start date (future start) and setup date (already started) will never bill"
+    if $self->start_date && $self->setup;
+
   $self->usernum($FS::CurrentUser::CurrentUser->usernum) unless $self->usernum;
 
   if ( $self->dbdef_table->column('manual_flag') ) {
@@ -757,6 +768,8 @@ sub cancel {
     map  { [ $_, $_->svc_x->table_info->{'cancel_weight'} ]; }
     qsearch( 'cust_svc', { 'pkgnum' => $self->pkgnum } )
   ) {
+    my $part_svc = $cust_svc->part_svc;
+    next if ( defined($part_svc) and $part_svc->preserve );
     my $error = $cust_svc->cancel( %svc_cancel_opt );
 
     if ( $error ) {
@@ -1407,7 +1420,6 @@ sub change {
 
 }
 
-use Data::Dumper;
 use Storable 'thaw';
 use MIME::Base64;
 sub process_bulk_cust_pkg {
@@ -2195,7 +2207,8 @@ sub _labels_short {
         while ( @values ) {
           my $detail = "$label: ";
           $detail .= shift(@values). ', '
-            while @values && length($detail.$values[0]) < 78;
+            while @values
+               && ( length($detail.$values[0]) < 78 || $detail eq "$label: " );
           $detail =~ s/, $//;
           push @labels, $detail;
         }
@@ -2598,6 +2611,7 @@ sub insert_discount {
     'amount'      => $self->discountnum_amount,
     'percent'     => $self->discountnum_percent,
     'months'      => $self->discountnum_months,
+    'setup'      => $self->discountnum_setup,
     #'disabled'    => $self->discountnum_disabled,
   };
 
@@ -3269,6 +3283,15 @@ sub _location_sql_where {
   ";
 }
 
+sub _X_show_zero {
+  my( $self, $what ) = @_;
+
+  my $what_show_zero = $what. '_show_zero';
+  length($self->$what_show_zero())
+    ? ($self->$what_show_zero() eq 'Y')
+    : $self->part_pkg->$what_show_zero();
+}
+
 =head1 SUBROUTINES
 
 =over 4