X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=httemplate%2Fedit%2Fpart_pkg.cgi;h=3e0a35466b47f95bb3a4f026170135bd5b97fcfa;hb=5e63ae96cf7d3e618c569c3fe12f6a6dae40038e;hp=a4123e1377c76e5b57ce032b215ab33544491709;hpb=a6d3e4dc73803cffad96fd4b6270b2fb5f4b0568;p=freeside.git diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index a4123e137..3e0a35466 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -1,302 +1,439 @@ - - -<% - -if ( $cgi->param('clone') && $cgi->param('clone') =~ /^(\d+)$/ ) { - $cgi->param('clone', $1); -} else { - $cgi->param('clone', ''); -} -if ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) { - $cgi->param('pkgnum', $1); -} else { - $cgi->param('pkgnum', ''); -} - -my ($query) = $cgi->keywords; -my $action = ''; -my $part_pkg = ''; -if ( $cgi->param('error') ) { - $part_pkg = new FS::part_pkg ( { - map { $_, scalar($cgi->param($_)) } fields('part_pkg') - } ); -} -if ( $cgi->param('clone') ) { - $action='Custom Pricing'; - my $old_part_pkg = - qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } ); - $part_pkg ||= $old_part_pkg->clone; -} elsif ( $query && $query =~ /^(\d+)$/ ) { - $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1}); - unless ( $part_pkg->plan ) { - $part_pkg->plan('flat'); - $part_pkg->plandata("setup=". $part_pkg->setup. "\n". - "recur=". $part_pkg->recur. "\n"); - } -} else { - $part_pkg ||= new FS::part_pkg {}; - $part_pkg->plan('flat'); -} -$action ||= $part_pkg->pkgpart ? 'Edit' : 'Add'; -my $hashref = $part_pkg->hashref; +<% include( 'elements/edit.html', + 'post_url' => popurl(1).'process/part_pkg.cgi', + 'name' => "Package definition", + 'table' => 'part_pkg', + #'viewall_dir' => 'browse', + 'viewall_url' => $p.'browse/part_pkg.cgi', + 'html_init' => include('/elements/init_overlib.html'). + $freq_changed, + 'html_bottom' => $html_bottom, + 'new_hashref_callback' => $new_hashref_callback, + 'new_object_callback' => $new_object_callback, + 'new_callback' => $new_callback, + 'edit_callback' => $edit_callback, + 'error_callback' => $error_callback, + + 'labels' => { + 'pkgpart' => 'Package Definition', + 'pkg' => 'Package (customer-visible)', + 'comment' => 'Comment (customer-hidden)', + 'classnum' => 'Package class', + 'promo_code' => 'Promotional code', + 'freq' => 'Recurring fee frequency', + 'setuptax' => 'Setup fee tax exempt', + 'recurtax' => 'Recurring fee tax exempt', + 'taxclass' => 'Tax class', + 'plan' => 'Price plan', + 'disabled' => 'Disable new orders', + 'pay_weight' => 'Payment weight', + 'credit_weight' => 'Credit weight', + 'agentnum' => '', + 'setup_fee' => 'Setup fee', + 'recur_fee' => 'Recurring fee', + 'bill_dst_pkgpart' => 'Include line item(s) from package', + 'svc_dst_pkgpart' => 'Include services of package', + }, + + 'fields' => [ + { field=>'clone', type=>'hidden', + curr_value_callback => + sub { shift->param('clone') }, + }, + { field=>'pkgnum', type=>'hidden', + curr_value_callback => + sub { shift->param('pkgnum') }, + }, -%> + { type => 'columnstart' }, + + {field=>'pkg', type=>'text', size=>40 }, #32 + {field=>'comment', type=>'text', size=>40 }, #32 + {field=>'classnum', type=>'select-pkg_class' }, + {field=>'disabled', type=>'checkbox', value=>'Y'}, + + { type => 'tablebreak-tr-title', + value => 'Pricing', #better name? + }, + { field => 'plan', + type => 'selectlayers-select', + options => [ keys %plan_labels ], + labels => \%plan_labels, + }, + { field => 'setup_fee', + type => 'money', + }, + { field => 'freq', + type => 'part_pkg_freq', + onchange => 'freq_changed', + }, + { field => 'recur_fee', + type => 'money', + disabled => sub { $recur_disabled }, + }, + + #price plan + #setup fee + #recurring frequency + #recurring fee (auto-disable) + + { type => 'columnnext' }, + + {type=>'justtitle', value=>'Taxation' }, + {field=>'setuptax', type=>'checkbox', value=>'Y'}, + {field=>'recurtax', type=>'checkbox', value=>'Y'}, + {field=>'taxclass', type=>'select-taxclass' }, + {field=>'taxproductnum', type=>'select-taxproduct' }, + + { type => 'tablebreak-tr-title', + value => 'Promotions', #better name? + }, + { field=>'promo_code', type=>'text', size=>15 }, + + { 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 => 'columnnext' }, + + { field=>'agent_type', + type => 'select-agent_types', + curr_value_callback => sub { + my($cgi, $object, $field) = @_; + #in the other callbacks..? hmm. + \@agent_type; + }, + }, + + { type => 'columnend' }, + + { 'type' => 'tablebreak-tr-title', + 'value' => 'Pricing add-ons', + }, + { 'field' => 'bill_dst_pkgpart', + 'type' => 'select-part_pkg', + 'm2_label' => 'Include line item(s) from package', + 'm2m_method' => 'bill_part_pkg_link', + 'm2m_dstcol' => 'dst_pkgpart', + 'm2_error_callback' => + &{$m2_error_callback_maker}('bill'), + }, - + { type => 'tablebreak-tr-title', + value => 'Services', + }, + { type => 'pkg_svc', }, + + { 'field' => 'svc_dst_pkgpart', + 'label' => 'Also include services from package: ', + 'type' => 'select-part_pkg', + 'm2_label' => 'Include services of package: ', + 'm2m_method' => 'svc_part_pkg_link', + 'm2m_dstcol' => 'dst_pkgpart', + 'm2_error_callback' => + &{$m2_error_callback_maker}('svc'), + }, -<% + { type => 'tablebreak-tr-title', + value => 'Price plan options', + }, + + ], -print header("$action Package Definition", menubar( - 'Main Menu' => popurl(2), - 'View all packages' => popurl(2). 'browse/part_pkg.cgi', -), ' onLoad="visualize()"'); + ) +%> +<%init> -print qq!Error: !, $cgi->param('error'), - "" - if $cgi->param('error'); +my $curuser = $FS::CurrentUser::CurrentUser; -#print '
'; -print ''; +die "access denied" + unless $curuser->access_right('Edit package definitions') + || $curuser->access_right('Edit global package definitions') + || ( $cgi->param('pkgnum') && $curuser->access_right('Customize customer package') ); -#if ( $cgi->param('clone') ) { -# print qq!!; -#} -#if ( $cgi->param('pkgnum') ) { -# print qq!!; -#} +#XXX +# - tr-part_pkg_freq: month_increments_only (from price plans) +# - test cloning +# - test errors cloning +# - test custom pricing +# - move the selectlayer divs away from lame layer_callback + +#my ($query) = $cgi->keywords; # -#print qq!!, -print "Package Part #", $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)"; +#my $part_pkg = ''; + +my @agent_type = (); +my $tax_override; + +my $clone_part_pkg = ''; + +my %options = (); +my $recur_disabled = 1; +my $error_callback = sub { + my($cgi, $object, $fields, $opt ) = @_; + (@agent_type) = $cgi->param('agent_type'); + $tax_override = $cgi->param('tax_override'); + $opt->{action} = 'Custom' if $cgi->param('clone'); + $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } ); + + $recur_disabled = $cgi->param('freq') ? 0 : 1; + + #some false laziness w/process + $cgi->param('plan') =~ /^(\w+)$/ or die 'unparsable plan'; + my $plan = $1; + my $options = $cgi->param($plan."__OPTIONS"); + my @options = split(',', $options); + %options = + map { my $optionname = $_; + my $param = $plan."__$optionname"; + my $value = join(', ', $cgi->param($param)); + ( $optionname => $value ); + } + @options; + + #$cgi->param($_, $options{$_}) foreach (qw( setup_fee recur_fee )); + $object->set($_ => scalar($cgi->param($_)) ) + foreach (qw( setup_fee recur_fee )); + +}; + +my $new_hashref_callback = sub { { 'plan' => 'flat' }; }; + +my $new_object_callback = sub { + my( $cgi, $hashref, $fields, $opt ) = @_; + + my $part_pkg = ''; + if ( $cgi->param('clone') ) { + $opt->{action} = 'Custom'; + $clone_part_pkg = qsearchs('part_pkg', { pkgpart=>$cgi->param('clone') } ); + $part_pkg = $clone_part_pkg->clone; + $part_pkg->disabled('Y'); + %options = $clone_part_pkg->options; + $part_pkg->set($_ => $option{$_}) + foreach (qw( setup_fee recur_fee )); + } else { + $part_pkg = FS::part_pkg->new( $hashref ); + $part_pkg->set($_ => '0') + foreach (qw( setup_fee recur_fee )); + } -print < -Package (customer-visable) -Comment (customer-hidden) + $part_pkg; -Frequency (months) of recurring fee +}; - +my $edit_callback = sub { + my( $cgi, $object, $fields ) = @_; -END + $recur_disabled = $object->freq ? 0 : 1; -unless ( $cgi->param('clone') ) { - print <
- - -END -} - -my $count = 0; -my @fixups = (); -foreach my $part_svc ( ( qsearch( 'part_svc', {} ) ) ) { - my $svcpart = $part_svc->svcpart; - my $pkg_svc = qsearchs( 'pkg_svc', { - 'pkgpart' => $cgi->param('clone') || $part_pkg->pkgpart, - 'svcpart' => $svcpart, - } ) || new FS::pkg_svc ( { - 'pkgpart' => $cgi->param('clone') || $part_pkg->pkgpart, - 'svcpart' => $svcpart, - 'quantity' => 0, - }); - #? #next unless $pkg_svc; - - push @fixups, "pkg_svc$svcpart"; - - unless ( defined ($cgi->param('clone')) && $cgi->param('clone') ) { - print '' if $count == 0 ; - print qq!"; - $count++; - if ($count == 2) - { - print ''; - $count = 0; - } - } else { - print qq!quantity || 0, qq!">\n!; - } -} - -unless ( $cgi->param('clone') ) { - print qq!! if ($count != 0) ; - print "
Quan.ServiceQuan.Service
quantity || 0, - qq!">!, $part_svc->getfield('svc'), "
"; -} - -# prolly should be in database -my %plans = ( - - 'flat' => { - 'name' => 'Flat rate', - 'fields' => { - 'setup_fee' => { 'name' => 'Setup fee for this package', - 'default' => 0, - }, - 'recur_fee' => { 'name' => 'Recurring fee for this package', - 'default' => 0, - }, - }, - 'setup' => 'what.setup_fee.value', - 'recur' => 'what.recur_fee.value', - }, - - 'flat_comission' => { - 'name' => 'Flat rate with recurring referral comission as credit', - 'fields' => { - 'setup_fee' => { 'name' => 'Setup fee for this package', - 'default' => 0, - }, - 'recur_fee' => { 'name' => 'Recurring fee for this package', - 'default' => 0, - }, - 'comission_amount' => { 'name' => 'Comission amount', - 'default' => 0, - }, - 'comission_depth' => { 'name' => 'Number of layers', - 'default' => 1, - }, - }, - 'setup' => 'what.setup_fee.value', - 'recur' => '\'my $error = $cust_pkg->cust_main->credit( \' + what.comission_amount.value + \' * scalar($cust_pkg->cust_main->referral_cust_pkg(\' + what.comission_depth.value+ \')), "commission" ); die $error if $error; \' + what.recur_fee.value + \';\'', - }, + (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1}); + $tax_override = + join (",", map {$_->taxclassnum} + qsearch( 'part_pkg_taxoverride', {'pkgpart' => $1} ) + ); -); +# join (",", map {$_->taxclassnum} +# $part_pkg->part_pkg_taxrate( 'cch', $conf->config('defaultloc') +# ); +# unless $tax_override; -%> + %options = $object->options; - -
-Price plan - - - -<% my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); } - split("\n", $part_pkg->plandata ); - #foreach my $layer ( 'konq_kludge', keys %plans ) { - foreach my $layer ( 'konq_kludge', keys %plans ) { - my $visibility = "hidden"; -%> - - -
- - - - -<% foreach my $f ( @fixups ) { %> - -<% } %> - -<% -if ( $cgi->param('clone') ) { - print qq!!; -} -if ( $cgi->param('pkgnum') ) { - print qq!!; -} -print qq!!, -%> +}; -<% my $href = $plans{$layer}->{'fields'}; - foreach my $field ( keys %{ $href } ) { %> -<%= $href->{$field}{'name'} %>: -
-<% } %> - - - -Setup expression

-Recurring espression

-
- -<% -print qq!
!; -%> +my $new_callback = sub { + my( $cgi, $object, $fields ) = @_; -
+ my $conf = new FS::Conf; + if ( $conf->exists('agent_defaultpkg') ) { + #my @all_agent_types = map {$_->typenum} qsearch('agent_type',{}); + @agent_type = map {$_->typenum} qsearch('agent_type',{}); + } - +}; + +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; + }; +}; + +my $freq_changed = <<'END'; + +END -{'freq'}) && $plans{$layer}->{'freq'} eq 'm'; + #foreach my $freq ( @freq ) { + # $html .= qq(