X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fedit%2Fpart_pkg.cgi;h=538ba3478699e1902a9f287dbed54cd541d9308a;hp=5a9bb109f695c52e9e11ec4658594bf8d45e3a22;hb=37591b61f8ad6fc5c5acb2fd8f520d2dbe4f1539;hpb=df676d82034cb63ff357f8d8ed0f95ce788fb98b diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 5a9bb109f..538ba3478 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -5,8 +5,7 @@ 'agent_virt' => 1, 'agent_null_right' => $edit_global, - 'agent_clone_extra_sql' => FS::part_pkg->curuser_pkgs_sql, - + 'agent_clone_extra_sql' => $agent_clone_extra_sql, #'viewall_dir' => 'browse', 'viewall_url' => $p.'browse/part_pkg.cgi', 'html_init' => include('/elements/init_overlib.html'). @@ -23,12 +22,14 @@ 'clone_callback' => $clone_callback, 'edit_callback' => $edit_callback, 'error_callback' => $error_callback, + 'field_callback' => $field_callback, 'labels' => { 'pkgpart' => 'Package Definition', 'pkg' => 'Package (customer-visible)', 'comment' => 'Comment (customer-hidden)', 'classnum' => 'Package class', + 'addon_classnum' => 'Restrict additional orders to package class', 'promo_code' => 'Promotional code', 'freq' => 'Recurring fee frequency', 'setuptax' => 'Setup fee tax exempt', @@ -37,6 +38,8 @@ 'taxproduct_select'=> 'Tax products', 'plan' => 'Price plan', 'disabled' => 'Disable new orders', + 'setup_cost' => 'Setup cost', + 'recur_cost' => 'Recur cost', 'pay_weight' => 'Payment weight', 'credit_weight' => 'Credit weight', 'agentnum' => 'Agent', @@ -44,6 +47,7 @@ 'recur_fee' => 'Recurring fee', 'bill_dst_pkgpart' => 'Include line item(s) from package', 'svc_dst_pkgpart' => 'Include services of package', + 'report_option' => 'Report classes', }, 'fields' => [ @@ -56,6 +60,8 @@ sub { shift->param('pkgnum') }, }, + { field=>'custom', type=>'hidden' }, + { type => 'columnstart' }, { field => 'pkg', @@ -71,6 +77,13 @@ onchange => 'agent_changed', }, {field=>'classnum', type=>'select-pkg_class' }, + ( $conf->exists('pkg-addon_classnum') + ? ( { field=>'addon_classnum', + type =>'select-pkg_class', + } + ) + : () + ), {field=>'disabled', type=>$disabled_type, value=>'Y'}, { type => 'tablebreak-tr-title', @@ -131,10 +144,10 @@ { field=>'promo_code', type=>'text', size=>15 }, { type => 'tablebreak-tr-title', - value => 'Line-item revenue recogition', #better name? + value => 'Cost tracking', #better name? }, - { field=>'pay_weight', type=>'text', size=>6 }, - { field=>'credit_weight', type=>'text', size=>6 }, + { field=>'setup_cost', type=>'money', }, + { field=>'recur_cost', type=>'money', }, { type => 'columnnext' }, @@ -148,10 +161,33 @@ }, }, + { type => 'tablebreak-tr-title', + value => 'Line-item revenue recogition', #better name? + }, + { field=>'pay_weight', type=>'text', size=>6 }, + { field=>'credit_weight', type=>'text', size=>6 }, + + { type => 'columnend' }, - { 'type' => 'tablebreak-tr-title', - 'value' => 'Pricing add-ons', + { 'type' => $report_option ? 'tablebreak-tr-title' + : 'hidden', + 'value' => 'Optional report classes', + 'field' => 'census_title', + }, + { 'field' => 'report_option', + 'type' => $report_option ? 'select-table' + : 'hidden', + 'table' => 'part_pkg_report_option', + 'name_col' => 'name', + 'hashref' => { 'disabled' => '' }, + 'multiple' => 1, + }, + + + { 'type' => 'tablebreak-tr-title', + 'value' => 'Pricing add-ons', + 'colspan' => 4, }, { 'field' => 'bill_dst_pkgpart', 'type' => 'select-part_pkg', @@ -160,6 +196,13 @@ 'm2m_dstcol' => 'dst_pkgpart', 'm2_error_callback' => &{$m2_error_callback_maker}('bill'), + 'm2_fields' => [ { 'field' => 'hidden', + 'type' => 'checkbox', + 'value' => 'Y', + 'curr_value' => '', + 'label' => 'Bundle', + }, + ], }, { type => 'tablebreak-tr-title', @@ -206,9 +249,25 @@ my $begin_callback = sub { my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden'; +#arg. access rights for cloning are Hard. +# on the one hand we don't really want cloning (customizing a package) to fail +# for want of finding the source package in normal usage +# on the other hand, we don't want people using the clone link to be able to +# see +my $agent_clone_extra_sql = + ' ( '. FS::part_pkg->curuser_pkgs_sql. + " OR ( part_pkg.custom = 'Y' ) ". + ' ) '; + my $conf = new FS::Conf; my $taxproducts = $conf->exists('enable_taxproducts'); +my $sth = dbh->prepare("SELECT COUNT(*) FROM part_pkg_report_option". + " WHERE disabled IS NULL OR disabled = '' ") + or die dbh->errstr; +$sth->execute or die $sth->errstr; +my $report_option = $sth->fetchrow_arrayref->[0]; + #XXX # - tr-part_pkg_freq: month_increments_only (from price plans) # - test cloning @@ -225,6 +284,7 @@ my %tax_override = (); my %taxproductnums = map { ($_->classnum => 1) } qsearch('usage_class', { 'disabled' => '' }); +my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) ); my %options = (); my $recur_disabled = 1; @@ -282,16 +342,30 @@ my $edit_callback = sub { $recur_disabled = $object->freq ? 0 : 1; - (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1}); + (@agent_type) = + map {$_->typenum} qsearch('type_pkgs', { 'pkgpart' => $object->pkgpart } ); + my @report_option = (); foreach ($object->options) { /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1); + /^report_option_(\d+)$/ && (push @report_option, $1); } foreach ($object->part_pkg_taxoverride) { $taxproductnums{$_->usage_class} = 1 if $_->usage_class; } + $cgi->param('report_option', join(',', @report_option)); + foreach my $field ( @$fields ) { + next unless ( + ref($field) eq 'HASH' && + $field->{field} && + $field->{field} eq 'report_option' + ); + #$field->{curr_value} = join(',', @report_option); + $field->{value} = join(',', @report_option); + } + %options = $object->options; $object->set($_ => $object->option($_)) @@ -321,12 +395,16 @@ my $clone_callback = sub { $opt->{action} = 'Custom'; #my $part_pkg = $clone_part_pkg->clone; - #this is all clone did anyway - $object->comment( '(CUSTOM) '. $object->comment ) - unless $object->comment =~ /^\(CUSTOM\) /; + #this is all clone does anyway + $object->custom('Y'); $object->disabled('Y'); + } else { #not when cloning... + + (@agent_type) = + map {$_->typenum} qsearch('type_pkgs',{ 'pkgpart' => $object->pkgpart } ); + } %options = $object->options; @@ -341,16 +419,25 @@ my $m2_error_callback_maker = sub { my $link_type = shift; #yay closures return sub { my( $cgi, $object ) = @_; - map { - new FS::part_pkg_link { - 'link_type' => $link_type, - 'src_pkgpart' => $object->pkgpart, - 'dst_pkgpart' => $_, - }; - } - grep $_, - map $cgi->param($_), - grep /^${link_type}_dst_pkgpart(\d+)$/, $cgi->param; + map { + + if ( /^${link_type}_dst_pkgpart(\d+)$/ && + ( my $dst = $cgi->param("${link_type}_dst_pkgpart$1") ) ) + { + + my $hidden = $cgi->param("${link_type}_dst_pkgpart__hidden$1") + || ''; + new FS::part_pkg_link { + 'link_type' => $link_type, + 'src_pkgpart' => $object->pkgpart, + 'dst_pkgpart' => $dst, + 'hidden' => $hidden, + }; + } else { + (); + } + } + $cgi->param; }; }; @@ -546,7 +633,6 @@ my %usage_class = map { ($_->classnum => $_->classname) } $usage_class{setup} = 'Setup'; $usage_class{recur} = 'Recurring'; -my @taxproductnums = (); my %taxproduct_fields = (); my $end_callback = sub { my( $cgi, $object, $fields, $opt ) = @_; @@ -611,4 +697,21 @@ my $taxproduct_values = sub { }; +my $field_callback = sub { + my ($cgi, $object, $fieldref) = @_; + + my $field = $fieldref->{field}; + if ($field eq 'taxproductnums') { + $fieldref->{value} = join(',', @taxproductnums); + } elsif ($field eq 'taxproduct_select') { + $fieldref->{options} = [ '(default)', @taxproductnums ]; + $fieldref->{labels} = { ( '(default)' => '(default)' ), + map {( $_ => ($usage_class{$_} || $_) )} + @taxproductnums + }; + $fieldref->{layer_fields} = \%taxproduct_fields; + $fieldref->{layer_values_callback} = $taxproduct_values; + } +}; +