+
+<% include('/elements/footer.html') %>
+<%init>
+
+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 $curuser = $FS::CurrentUser::CurrentUser;
+
+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') );
+
+my ($query) = $cgi->keywords;
+
+my $conf = new FS::Conf;
+my $part_pkg = '';
+my @agent_type = ();
+my $tax_override;
+my @all_agent_types = map {$_->typenum} qsearch('agent_type',{});
+if ( $cgi->param('error') ) {
+ $part_pkg = new FS::part_pkg ( {
+ map { $_, scalar($cgi->param($_)) } fields('part_pkg')
+ } );
+ (@agent_type) = $cgi->param('agent_type');
+ $tax_override = $cgi->param('tax_override');
+}
+
+my $action = '';
+my $clone_part_pkg = '';
+my $pkgpart = '';
+if ( $cgi->param('clone') ) {
+ $pkgpart = $cgi->param('clone');
+ #$action = 'Custom Pricing';
+ $action = 'Custom';
+ $clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
+ $part_pkg ||= $clone_part_pkg->clone;
+ $part_pkg->disabled('Y') unless $cgi->param('error');
+} elsif ( $query && $query =~ /^(\d+)$/ ) {
+ (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
+ unless $part_pkg;
+ unless ($part_pkg) {
+ $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;
+ }
+ $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
+ $pkgpart = $part_pkg->pkgpart;
+} else {
+ unless ( $part_pkg ) {
+ $part_pkg = new FS::part_pkg {};
+ $part_pkg->plan('flat');
+ @agent_type = @all_agent_types if $conf->exists('agent_defaultpkg');
+
+ }
+}
+unless ( $part_pkg->plan ) { #backwards-compat
+ $part_pkg->plan('flat');
+ $part_pkg->plandata("setup_fee=". $part_pkg->setup. "\n".
+ "recur_fee=". $part_pkg->recur. "\n");
+}
+$action ||= $part_pkg->pkgpart ? 'Edit' : 'Add';
+my $hashref = $part_pkg->hashref;
+my $taxproduct_description = $part_pkg->taxproduct_description;
+
+</%init>