Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / edit / part_pkg.cgi
index 778a026..9f5510d 100755 (executable)
@@ -28,7 +28,7 @@
 
      'onsubmit'              => 'confirm_submit',
 
-     'labels' => { 
+     'labels' => {
                    'pkgpart'          => 'Package Definition',
                    'pkg'              => 'Package',
                    %locale_field_labels,
                    'svc_dst_pkgpart'  => 'Include services of package',
                    'supp_dst_pkgpart' => 'When ordering package, also order',
                    'report_option'    => 'Report classes',
-                   'fcc_ds0s'         => 'Voice-grade equivalents',
-                   'fcc_voip_class'   => 'Category',
                    'delay_start'      => 'Default delay (days)',
+                   'adjourn_months'   => 'Suspend the package after ',
+                   'contract_end_months' => 'Contract ends after ',
+                   'expire_months'    => 'Cancel the package after ',
+                   'change_to_pkgpart'=> 'and replace it with ',
                  },
 
      'fields' => [
                          sort $conf->config('currencies')
                      ),
 
+                     ( $conf->exists('part_pkg-delay_start')
+                       ? ( { type  => 'tablebreak-tr-title',
+                             value => 'Delayed start',
+                           },
+                           { field => 'delay_start',
+                             type => 'text', size => 6 },
+                         )
+                       : ()
+                     ),
+
+                     { type   => 'tablebreak-tr-title',
+                       value  => 'Limited duration',
+                     },
+                     { field  => 'adjourn_months',
+                       type   => 'select-months',
+                     },
+                     { field  => 'contract_end_months',
+                       type   => 'select-months',
+                     },
+                     { field  => 'expire_months',
+                       type   => 'select-expire_months',
+                     },
+                     { field  => 'change_to_pkgpart',
+                       type   => 'select-part_pkg',
+                       extra_sql  => sub { $pkgpart
+                        ? "AND pkgpart != $pkgpart"
+                        : ''
+                       },
+                       empty_label => 'no package',
+                     },
+
                      #price plan
                      #setup fee
                      #recurring frequency
                        type  => 'hidden',
                        value => join(',', @taxproductnums),
                      },
-                     { field => 'taxproduct_select',
-                       type  => 'selectlayers',
-                       options => [ '(default)', @taxproductnums ],
-                       curr_value => '(default)',
-                       labels  => { ( '(default)' => '(default)' ),
-                                    map {($_=>$usage_class{$_})}
-                                    @taxproductnums
-                                  },
-                       layer_fields => \%taxproduct_fields,
-                       layer_values_callback => $taxproduct_values,
-                       layers_only  =>   !$taxproducts,
-                       cell_style   => ( !$taxproducts
-                                         ? 'display:none'
-                                         : ''
-                                       ),
+                     #{ field => 'taxproduct_select',
+                     #  type  => 'selectlayers',
+                     #  options => [ '(default)', @taxproductnums ],
+                     #  curr_value => '(default)',
+                     #  labels  => { ( '(default)' => '(default)' ),
+                     #               map {($_=>$usage_class{$_})}
+                     #               @taxproductnums
+                     #             },
+                     #  layer_fields => \%taxproduct_fields,
+                     #  layer_values_callback => $taxproduct_values,
+                     #  layers_only  =>   !$taxproducts,
+                     #  cell_style   => ( !$taxproducts
+                     #                    ? 'display:none'
+                     #                    : ''
+                     #                  ),
+                     #},
+                     { field => 'taxproductnum',
+                       type  => 'part_pkg-taxproducts',
+                       include_opt_callback =>
+                         sub { pkgpart => $_[0]->pkgpart },
                      },
 
                      { type  => 'tablebreak-tr-title',
                          )
                      ),
 
-                     ( $conf->exists('part_pkg-delay_start')
-                       ? ( { type  => 'tablebreak-tr-title',
-                             value => 'Delayed start',
-                           },
-                           { field => 'delay_start',
-                             type => 'text', size => 6 },
-                         )
-                       : ()
-                     ),
-
                    { type => 'columnnext' },
 
                      {type=>'justtitle', value=>'Agent (reseller) types' },
@@ -416,7 +444,7 @@ my $agent_clone_extra_sql =
   ' ) ';
 
 my $conf = new FS::Conf;
-my $taxproducts = $conf->exists('enable_taxproducts');
+my $taxproducts = $conf->config('tax_data_vendor') ne '';
 
 my $fcc_opts = $conf->exists('part_pkg-show_fcc_options');
 
@@ -561,6 +589,11 @@ my $error_callback = sub {
     'cgiparam'
   );
 
+  if ( $cgi->param('error') =~ / is suggested with / ) {
+    #yeah, detection is a shitty kludge, but we don't have exception objects
+    $opt->{form_init} = '<INPUT TYPE="checkbox" NAME="part_pkg_restrict_soft_override" VALUE="Y"> Override suggestion<BR><BR>';
+  }
+
 };
 
 my $new_hashref_callback = sub { { 'plan' => 'flat' }; };
@@ -967,8 +1000,17 @@ my $html_bottom = sub {
             'msg'       => q|You must set the 'suspend_credit_type' option in Configuration->Settings to gain access to this option.|,
             'are_met'   => sub{
                 my $conf = new FS::conf;
-                my @suspend_credit_type_conf = qsearch('conf', { 'name' => 'suspend_credit_type' } );
-                return 1 if (exists($suspend_credit_type_conf[0]) && $suspend_credit_type_conf[0]->{Hash}{value});
+                my @conf_info = qsearch('conf', { 'name' => 'suspend_credit_type' } );
+                return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
+                return 0;
+            }
+        },
+        'unused_credit_cancel' => {
+            'msg'       => q|You must set the 'cancel_credit_type' option in Configuration->Settings to gain access to this option.|,
+            'are_met'   => sub{
+                my $conf = new FS::conf;
+                my @conf_info = qsearch('conf', { 'name' => 'cancel_credit_type' } );
+                return 1 if (exists($conf_info[0]) && $conf_info[0]->{Hash}{value});
                 return 0;
             }
         }
@@ -1108,9 +1150,9 @@ my $html_bottom = sub {
     '<SCRIPT TYPE="text/javascript">'.
       include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 );
 
-  $return .=
-    "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
-      if $taxproducts;
+#  $return .=
+#    "taxproduct_selectchanged(document.getElementById('taxproduct_select'));\n"
+#      if $taxproducts;
 
   $return .= '</SCRIPT>';
 
@@ -1201,6 +1243,11 @@ my $field_callback = sub {
                            };
     $fieldref->{layer_fields} = \%taxproduct_fields;
     $fieldref->{layer_values_callback} = $taxproduct_values;
+  } elsif ($field eq 'taxproductnum') { # part_pkg-taxproduct, new style
+    if ( !$taxproducts ) {
+      # then make the widget go away
+      $fieldref->{type} = 'hidden';
+    }
   }
 };