X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fpart_pkg.cgi;h=39c0ac3c1e80ce90b649dbb8a6bb8ab54cc378af;hb=95ce32b3b4d3957a90ad0e999f75396063c22b94;hp=5eccc1e1e0058bea77eb169adf0875cf621a1f4a;hpb=05eafa5ab3ded207d716685b32edf6946187514a;p=freeside.git diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 5eccc1e1e..39c0ac3c1 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -1,301 +1,430 @@ - - -<% - -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}); -} else { - $part_pkg ||= new FS::part_pkg {}; - $part_pkg->plan('flat'); -} -unless ( $part_pkg->plan ) { #backwards-compat - $part_pkg->plan('flat'); - $part_pkg->plandata("setup=". $part_pkg->setup. "\n". - "recur=". $part_pkg->recur. "\n"); -} -$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' }, + { field=>'pkgnum', type=>'hidden' }, + + { 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', + }, + + ], + + ) %> +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; - - -<% -print header("$action Package Definition", menubar( - 'Main Menu' => popurl(2), - 'View all packages' => popurl(2). 'browse/part_pkg.cgi', -), ' onLoad="visualize()"'); + $part_pkg->set($_ => '0') + foreach (qw( setup_fee recur_fee )); -print qq!Error: !, $cgi->param('error'), - "" - if $cgi->param('error'); + $part_pkg; -#print '
'; -print ''; +}; -#if ( $cgi->param('clone') ) { -# print qq!!; -#} -#if ( $cgi->param('pkgnum') ) { -# print qq!!; -#} -# -#print qq!!, -print "Package Part #", $hashref->{pkgpart} ? $hashref->{pkgpart} : "(NEW)"; +my $edit_callback = sub { + my( $cgi, $object, $fields ) = @_; -print < -Package (customer-visable) -Comment (customer-hidden) + $recur_disabled = $object->freq ? 0 : 1; -Frequency (months) of recurring fee + (@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; -END + %options = $object->options; -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 + \';\'', - }, + $object->set($_ => $object->option($_)) + foreach (qw( setup_fee recur_fee )); -); +}; -%> +my $new_callback = sub { + my( $cgi, $object, $fields ) = @_; - -
-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!
!; -%> -
- - + } -<% } %> + +END -{'freq'}) && $plans{$layer}->{'freq'} eq 'm'; + #foreach my $freq ( @freq ) { + # $html .= qq(