From: Ivan Kohler Date: Mon, 19 Jan 2015 10:29:29 +0000 (-0800) Subject: import package definitions, RT#32639 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=b4aea58e0d04ff1930397e0f96ecdc50748b748b import package definitions, RT#32639 --- diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index fd5f29762..a1c87769e 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -1695,6 +1695,7 @@ sub process_batch_import { #? default_csv => $opt->{default_csv}, postinsert_callback => $opt->{postinsert_callback}, + insert_args_callback => $opt->{insert_args_callback}, ); if ( $opt->{'batch_namecol'} ) { @@ -1780,6 +1781,9 @@ sub batch_import { my $preinsert_callback = ''; $preinsert_callback = $param->{'preinsert_callback'} if $param->{'preinsert_callback'}; + my $insert_args_callback = ''; + $insert_args_callback = $param->{'insert_args_callback'} + if $param->{'insert_args_callback'}; if ( $param->{'format'} ) { @@ -2089,7 +2093,12 @@ sub batch_import { next if exists $param->{skiprow} && $param->{skiprow}; } - my $error = $record->insert; + my @insert_args = (); + if ( $insert_args_callback ) { + @insert_args = &{$insert_args_callback}($record, $param); + } + + my $error = $record->insert(@insert_args); if ( $error ) { $dbh->rollback if $oldAutoCommit; diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index ee167b19f..a4e1f1e52 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2126,6 +2126,7 @@ sub tables_hashref { 'part_pkg' => { 'columns' => [ 'pkgpart', 'serial', '', '', '', '', + 'pkgpartbatch', 'varchar', 'NULL', $char_d, '', '', 'pkg', 'varchar', '', $char_d, '', '', 'comment', 'varchar', 'NULL', 2*$char_d, '', '', 'promo_code', 'varchar', 'NULL', $char_d, '', '', diff --git a/FS/FS/part_pkg/Import.pm b/FS/FS/part_pkg/Import.pm new file mode 100644 index 000000000..9e9044e7f --- /dev/null +++ b/FS/FS/part_pkg/Import.pm @@ -0,0 +1,76 @@ +package FS::part_pkg::Import; + +use strict; +use FS::Record; +use FS::part_pkg; + +=head1 NAME + +FS::part_pkg::Import - Batch customer importing + +=head1 SYNOPSIS + + use FS::part_pkg::Import; + + #ajax helper + use FS::UI::Web::JSRPC; + my $server = + new FS::UI::Web::JSRPC 'FS::part_pkg::Import::process_batch_import', $cgi; + print $server->process; + +=head1 DESCRIPTION + +Batch package definition importing. + +=head1 SUBROUTINES + +=item process_batch_import + +Load a batch import as a queued JSRPC job + +=cut + +sub process_batch_import { + my $job = shift; + + my $opt = { 'table' => 'part_pkg', + 'params' => [qw( agentnum pkgpartbatch )], + 'formats' => { 'default' => [ + 'agent_pkgpartid', + 'pkg', + 'comment', + 'freq', + 'plan', + 'setup_fee', + 'recur_fee', + 'setup_cost', + 'recur_cost', + 'classnum', + 'taxclass', + ], + }, + 'insert_args_callback' => sub { + my $part_pkg = shift; + ( 'options' => { 'setup_fee' => $part_pkg->get('setup_fee'), + 'recur_fee' => $part_pkg->get('recur_fee'), + }, + ); + }, + #'default_csv' => 1, + }; + + FS::Record::process_batch_import( $job, $opt, @_ ); + +} + +=head1 BUGS + +Not enough documentation. + +=head1 SEE ALSO + +L, L + +=cut + +1; diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 5eeed8488..f5284e708 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -196,7 +196,7 @@ while (1) { dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile'); #auto-use classes... - if ( $ljob->job =~ /(FS::(part_export|cust_main|cust_pkg|Cron)::\w+)::/ + if ( $ljob->job =~ /(FS::(part_export|cust_main|cust_pkg|part_pkg|Cron)::\w+)::/ || $ljob->job =~ /(FS::\w+)::/ ) { diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi index 1fc0c49a3..a2f79e9b0 100755 --- a/httemplate/browse/part_pkg.cgi +++ b/httemplate/browse/part_pkg.cgi @@ -76,6 +76,10 @@ if ( $cgi->param('classnum') =~ /^(\d+)$/ ) { } $cgi->delete('classnum'); +if ( $cgi->param('pkgpartbatch') =~ /^([\w\/\-\:\. ]+)$/ ) { + push @where, "pkgpartbatch = '$1' "; +} + if ( $cgi->param('missing_recur_fee') ) { push @where, "NOT EXISTS ( SELECT 1 FROM part_pkg_option WHERE optionname = 'recur_fee' diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index cbe5378bd..0615ff762 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -439,12 +439,13 @@ $report_menu{'SQL Query'} = [ $fsurl.'search/report_sql.html', 'SQL Query'] if $curuser->access_right('Raw SQL'); tie my %tools_importing, 'Tie::IxHash', - 'Customers' => [ $fsurl.'misc/cust_main-import.cgi', '' ], - 'Customer packages' => [ $fsurl.'misc/cust_pkg-import.html', '' ], - 'Customer comments' => [ $fsurl.'misc/cust_main_note-import.html', '' ], - 'One-time charges' => [ $fsurl.'misc/cust_main-import_charges.cgi', '' ], - 'Payments' => [ $fsurl.'misc/cust_pay-import.cgi', '' ], - 'Credits' => [ $fsurl.'misc/cust_credit-import.html', '' ], + 'Customers' => [ $fsurl.'misc/cust_main-import.cgi', '' ], + 'Package definitions' => [ $fsurl.'misc/part_pkg-import.html', '' ], + 'Customer packages' => [ $fsurl.'misc/cust_pkg-import.html', '' ], + 'Customer comments' => [ $fsurl.'misc/cust_main_note-import.html', '' ], + 'One-time charges' => [ $fsurl.'misc/cust_main-import_charges.cgi', '' ], + 'Payments' => [ $fsurl.'misc/cust_pay-import.cgi', '' ], + 'Credits' => [ $fsurl.'misc/cust_credit-import.html', '' ], 'Phone numbers (DIDs)' => [ $fsurl.'misc/phone_avail-import.html', '' ], 'Call Detail Records (CDRs)' => [ $fsurl.'misc/cdr-import.html', '' ], ; diff --git a/httemplate/misc/cust_pkg-import.html b/httemplate/misc/cust_pkg-import.html index 94e7dd926..e0c0c7ff4 100644 --- a/httemplate/misc/cust_pkg-import.html +++ b/httemplate/misc/cust_pkg-import.html @@ -1,6 +1,6 @@ -<% include("/elements/header.html",'Batch Package Import') %> +<& /elements/header.html, 'Customer package import' &> -Import a file containing package records. +Import a file containing customer packages.

<& /elements/form-file_upload.html, @@ -8,19 +8,18 @@ Import a file containing package records. 'action' => 'process/cust_pkg-import.html', 'num_files' => 1, 'fields' => [ 'agentnum', 'pkgbatch', 'format' ], - 'message' => 'Package import successful', + 'message' => 'Customer package import successful', 'url' => $p."search/cust_pkg.cgi?pkgbatch=$pkgbatch", 'onsubmit' => "document.PackageImportForm.submitButton.disabled=true;" &> <% &ntable("#cccccc", 2) %> - <% include( '/elements/tr-select-agent.html', - #'curr_value' => '', #$agentnum, - 'label' => "Agent", - 'empty_label' => 'Select agent', - ) - %> + <& /elements/tr-select-agent.html, + #'curr_value' => '', #$agentnum, + 'label' => "Agent", + 'empty_label' => 'Select agent', + &> @@ -43,11 +42,10 @@ Import a file containing package records. - <% include( '/elements/file-upload.html', - 'field' => 'file', - 'label' => 'Filename', - ) - %> + <& /elements/file-upload.html, + 'field' => 'file', + 'label' => 'Filename', + &> @@ -171,7 +169,7 @@ Field information:
-<% include('/elements/footer.html') %> +<& /elements/footer.html &> <%once> diff --git a/httemplate/misc/part_pkg-import.html b/httemplate/misc/part_pkg-import.html new file mode 100644 index 000000000..aed734aac --- /dev/null +++ b/httemplate/misc/part_pkg-import.html @@ -0,0 +1,116 @@ +<& /elements/header.html, 'Import package definitions' &> + +Import a file containing package definitions. +

+ +<& /elements/form-file_upload.html, + 'name' => 'PackageDefImportForm', + 'action' => 'process/part_pkg-import.html', + 'num_files' => 1, + 'fields' => [ 'agentnum', 'pkgpartbatch', 'format' ], + 'message' => 'Package definition import successful', + 'url' => $p."browse/part_pkg.cgi?pkgpartbatch=$pkgpartbatch", + 'onsubmit' => "document.PackageDefImportForm.submitButton.disabled=true;" +&> + +<% &ntable("#cccccc", 2) %> + + <& /elements/tr-select-agent.html, + #'curr_value' => '', #$agentnum, + 'label' => "Agent", + + 'disable_empty' => 1, + #this doesn't work yet, no type_pkgs records are inserted + #'empty_label' => '(global)', + + #disable_empty => ! $acl_edit_global, + &> + + + + + + Format + + + + + + <& /elements/file-upload.html, + 'field' => 'file', + 'label' => 'Filename', + &> + + + + + + + + + + + +
+Uploaded files can be CSV (comma-separated value) files or Excel spreadsheets. The file should have a .CSV or .XLS extension. +

+ +Default format has the following field order: agent_pkgpartid, pkg<%$req%>, comment<%$req%>, freq<%$req%>, plan<%$req%>, setup_fee<%$req%>, recur_fee<%$req%>, setup_cost, recur_cost, classnum, taxclass + +

+ +<%$req%> Required fields +

+ +Field information: + +
    + +
  • agent_pkgpartid: Current product ID or code + +
  • pkg: Package name (customer-visible) + +
  • comment: Package comment (customer-hidden) + +
  • freq: Recurring fee frequency - 0 for one-time charges, a number of months (i.e. 1 for months, 12 for yearly), or a number followed by h, d or w for hours, days or weeks. + +
  • plan: Price plan, i.e. flat, prorate, voip_cdr, etc. + +
  • setup_fee: Setup price + +
  • recur_fee: Recurring price + +
  • setup_cost: Setup cost + +
  • recur_cost: Recurring cost + +
  • classnum: Package class (integer) + +
  • taxclass: Tax class (string) + +
+ +
+ +<& /elements/footer.html &> + +<%once> + +my $req = qq!*!; + + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Import'); + +my $pkgpartbatch = + time2str('webimport-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time); + + diff --git a/httemplate/misc/process/part_pkg-import.html b/httemplate/misc/process/part_pkg-import.html new file mode 100644 index 000000000..f951a21c3 --- /dev/null +++ b/httemplate/misc/process/part_pkg-import.html @@ -0,0 +1,10 @@ +<% $server->process %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Import'); + +my $server = + new FS::UI::Web::JSRPC 'FS::part_pkg::Import::process_batch_import', $cgi; + +